日期:2014-05-18 浏览次数:20864 次
protected void Page_Load(object sender, EventArgs e) { if (vip) { System.Web.UI.HtmlControls.HtmlLink hf2 = new System.Web.UI.HtmlControls.HtmlLink(); hf2.Attributes["type"] = "text/css"; hf2.Attributes["rel"] = "Stylesheet"; hf2.Href = "../css/hf2.css"; this.Header.Controls.Add(hf2); } else { System.Web.UI.HtmlControls.HtmlLink hf = new System.Web.UI.HtmlControls.HtmlLink(); hf.Attributes["type"] = "text/css"; hf.Attributes["rel"] = "Stylesheet"; hf.Href = "../css/hf.css"; this.Header.Controls.Add(hf); System.Web.UI.HtmlControls.HtmlLink tanceng = new System.Web.UI.HtmlControls.HtmlLink(); tanceng.Attributes["type"] = "text/css"; tanceng.Attributes["rel"] = "Stylesheet"; tanceng.Href = "../css/tanceng.css"; this.Header.Controls.Add(tanceng); } }
------解决方案--------------------
bool vip = true; HtmlLink link = new HtmlLink(); link.Attributes.Add("type", "text/css"); link.Attributes.Add("rel", "stylesheet"); if (vip) link.Attributes.Add("href", "css/vip.css"); else link.Attributes.Add("href", "css/normal.css"); Page.Header.Controls.Add(link);