overview: code piece of hh.weblog asp.net动态添加外部CSS文件或JS文件

香水坏坏 发表于 2007-8-16 [HH.Weblog]
C#代码
  1. public void AddPageHeaderLink(string virtualPath ,bool isJS)   
  2.         {   
  3.             System.Web.UI.HtmlControls.HtmlGenericControl link;   
  4.             if (!isJS)   
  5.             {   
  6.                 link = new System.Web.UI.HtmlControls.HtmlGenericControl( "link" );   
  7.                 link.Attributes.Add( "type""text/css");   
  8.                 link.Attributes.Add( "rel""stylesheet");   
  9.                 link.Attributes.Add( "href", virtualPath );   
  10.             }   
  11.             else  
  12.             {   
  13.                 link = new System.Web.UI.HtmlControls.HtmlGenericControl( "script" );   
  14.                 link.Attributes.Add( "language" , "javascript");   
  15.                 link.Attributes.Add( "type""text/javascript");   
  16.                 link.Attributes.Add( "src", virtualPath );   
  17.             }   
  18.                
  19.             Header.Controls.Add(link);   
  20.         }  
1358 3 标签:aspnet Blog程序 解决方案 
访客评论
  • cstyle    [2007-11-30]
    好文章,找了好久,總算是找到辦法了,太感謝樓主了
  • fx2    [2007-8-18]
    超级好文,没见过这么好的文!!!
  • fx    [2007-8-17]
    太佩服了,好文
发表评论
  • 你的姓名:
  • 你的网站:
  •   EMAIL:   
  • 评论内容:
  • 私人