• 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.         }  
    Hits: 1358  Feedback: 3  标签:aspnet Blog程序 解决方案  Trackback  Permalink: http://www.aspstat.com/60