Adding StyleSheets Programmatically in Asp.Net

前端 未结 4 1229
粉色の甜心
粉色の甜心 2020-12-03 13:51

I want to add StyleSheets programmatically in the head section but one of the examples I saw seemed to need to many lines of code to add just one style sheet even though I m

4条回答
  •  春和景丽
    2020-12-03 14:10

    I'll paste the thing which worked for me:

    HtmlLink link = new HtmlLink();
    //Add appropriate attributes
    link.Attributes.Add("rel", "stylesheet");
    link.Attributes.Add("type", "text/css");
    link.Href = "/Resources/CSS/NewStyles.css";
    link.Attributes.Add("media", "screen, projection");
    //add it to page head section
    this.Page.Header.Controls.Add(link);
    

    Even I searched a lot on this, I'd to add a overriding style sheet when a button is clicked. I used the above code and it worked perfectly to me.

提交回复
热议问题