为何会这样?
a.aspx页面:
<head runat="server">
<title>Te</title>
<link href="<%=css %>" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div>
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" class="login_toptext"><a href="login.aspx">Login</a></td>
<td> </td>
</tr>
</table>
</div>
</form>
</body>
a.cs代码:
public string css;
protected void Page_Load(object sender, EventArgs e)
{
css = "css/main.css";
}
在运行后,不正常。。查看源代码变成了这样:
..
</title><link href="<%=css %>" rel="stylesheet" type="text/css" /></head>
<body>
<form name="form1" method="post" action="CSSFront.aspx" id="form1">
<div>
..
为什么呢??该怎么样解决?谢谢
------解决方案--------------------原因不详,解决办法可以试一下这么几个:
1、href="<%=css %>" 去掉引号
2、<head runat="server"> 去掉runat="server"
3、改成<link rel="stylesheet" type="text/css" runat="server" id="link1" />,后台Page_Load中加上link.Href=css
4、前台中去掉<link href="<%=css %>" rel="stylesheet" type="text/css" />,后台Page_Load中加上
System.Web.UI.HtmlControls.HtmlLink link = new System.Web.UI.HtmlControls.HtmlLink();
link.Attributes.Add("href", css);(或者link.Href=css)
link.Attributes.Add("ref", "stylesheet");
link.Attributes.Add("type", "text/css");
Page.Header.Controls.Add(link);
------解决方案--------------------
HTML code
<head id="Head1" runat="server">
<title>Te</title>
</head>
<body>
<link href="<%=css %>" rel="stylesheet" type="text/css" />
<form id="form1" runat="server">
<div>
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" class="login_toptext">
<a href="login.aspx">Login</a>
</td>
<td>
</td>
</tr>
</table>
</div>
</form>
</body>
------解决方案--------------------
<link href=<%=css %> 去掉引号