钟会吧:动态加载CSS文件

来源:百度文库 编辑:中财网 时间:2024/04/30 15:29:55
 方法一:

WebForm1


private void Button1_Click(object sender, System.EventArgs e)
        {Page.RegisterStartupScript("css",@"");
        } 
方法二:--- 戏子的方法..嘻..抄来的...

        WebForm1
        
    
private void Button2_Click(object sender, System.EventArgs e)
        {
            System.Web.UI.Control a =  Page.FindControl("myplaceholder");
            System.Web.UI.HtmlControls.HtmlGenericControl objLink = new HtmlGenericControl("LINK");
            objLink.Attributes.Add("rel","stylesheet");
            objLink.Attributes.Add("type","text/css");
            objLink.Attributes.Add("href","StyleSheet1.css");
            objLink=objLink;
            a.Controls.Add(objLink);
        }
[注]  asp:placeholder  这是控件是主要是起"占位符的做用"