Asp.net dynamic reference style sheet code

Source: Internet
Author: User

1. Add a CSS Style: style Style = new Style ();
Style. ForeColor = System. Drawing. Color. Navy;
Style. BackColor = System. Drawing. Color. LightGray;
This. Header. StyleSheet. CreateStyleRule (style, null, "body ");
2. link the external CSS style sheet: HtmlLink link = new HtmlLink ();
Link. Attributes. Add ("type", "text/css ");
Link. Attributes. Add ("rel", "stylesheet ");
Link. Attributes. Add ("href ","~ /Newstyle.css ");
This. Header. Controls. Add (link );
Method 3 aa. aspx. cs public string m_StyleSrc = string. Empty; // public variable, Style File Path
Private void Page_Load (object sender, System. EventArgs e ){
M_StyleSrc = "../xxx.css"; // value assigned during page loading}
}
Aa. aspx <LINK href = "<% = m_StyleSrc %>" type = "text/css" rel = "stylesheet">
Method 4: I have not tried the following method. I wonder if it can be used.
Protected void Page_Onload (object sender, EventArgs e ){
Page. StyleSheetTheme = "../css/infomore.css ";
}
Method 5 page:
<Link href = "" rel = "stylesheet" type = "text/css" id = "css" runat = "server"/>
Background
This.css. Href = "css file path ";

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.