为什么用HtmlLink类添加样式表在网页头部不成功勒呢请高手解决
CS代码:
HtmlLink link1 = new HtmlLink();
link1.Href = "mode/" + this.Y_recent + "/css/master.css";
link1.Attributes.Add("rel", "stylesheet");
link1.Attributes.Add("type", "text/css");
this.Head1.Controls.Add(link1);
IL代码:
L_0184: newobj instance void [System.Web]System.Web.UI.HtmlControls.HtmlLink::.ctor()
L_0189: stloc.s link1
L_018b: ldloc.s link1
L_018d: ldstr "mode/"
L_0192: ldarg.0
L_0193: ldfld string yhw.lp_Default::Y_recent
L_0198: ldstr "/css/master.css"
L_019d: call string string::Concat(string, string, string)
L_01a2: callvirt instance void [System.Web]System.Web.UI.HtmlControls.HtmlLink::set_Href(string)
L_01a7: ldloc.s link1
L_01a9: callvirt instance [System.Web]System.Web.UI.AttributeCollection [System.Web]System.Web.UI.HtmlControls.HtmlControl::get_Attributes()
L_01ae: ldstr "rel"
L_01b3: ldstr "stylesheet"
L_01b8: callvirt instance void [System.Web]System.Web.UI.AttributeCollection::Add(string, string)
L_01bd: ldloc.s link1
L_01bf: callvirt instance [System.Web]System.Web.UI.AttributeCollection [System.Web]System.Web.UI.HtmlControls.HtmlControl::get_Attributes()
L_01c4: ldstr "type"
L_01c9: ldstr "text/css"
L_01ce: callvirt instance void [System.Web]System.Web.UI.AttributeCollection::Add(string, string)
L_01d3: ldarg.0
L_01d4: ldfld [System.Web]System.Web.UI.HtmlControls.HtmlHead yhw.lp_Default::Head1
L_01d9: callvirt instance [System.Web]System.Web.UI.ControlCollection [System.Web]System.Web.UI.Control::get_Controls()
L_01de: ldloc.s link1
L_01e0: callvirt instance void [System.Web]System.Web.UI.ControlCollection::Add([System.Web]System.Web.UI.Control)
------解决方案--------------------this.Header.Controls.Add(link1);
<head>标签可能没有runat="server"
------解决方案--------------------会不会是路径有问题,你再检查下路径。
------解决方案--------------------
应该不是这个地方的问题,你新建一个空白页面放在Page_Load中测试下肯定可以的