ASP.NET中后台注册css脚本

在写UserControl的时候,有时候会向调用页面注册css文件的引用。

 

c#

代码
//向调用页面注册css文件
HtmlGenericControl _CssFile = new HtmlGenericControl("link");
_CssFile.ID
= "CssFile";
_CssFile.Attributes[
"rel"] = "stylesheet";
_CssFile.Attributes[
"type"] = "text/css";
_CssFile.Attributes[
"href"] = "UserControl/ImgToggle/163Switcher/style/style.css";

//if (this.FindControl(_CssFile.ID) == null)
//{
     this.Page.Header.Controls.Add(_CssFile);
//}

 

运行结果:

代码
  <link id="CssFile" rel="stylesheet" type="text/css"
    href
="UserControl/ImgToggle/163Switcher/style/style.css"></link>

 

 

 

posted @ 2010-10-04 13:52  RyanBell  阅读(1484)  评论(0编辑  收藏  举报