Using MasterPage to reference external CSS files

Source: Internet
Author: User
First, if the <link> label is added outside the <asp: Content> label on the page where MasterPage is applied to reference the CSS file, a compilation error will occur. If the CSS file is referenced in the <asp: Content> label, an incorrect interpretation will occur. referencing a CSS file in the

In addition, compared with this method, there is a simple Hack. First, add the <link> tag to MasterPage, but the herf attribute is empty. <Head runat = "server">
<Link id = "cssStyleSheet1" rel = "stylesheet" type = "text/css" runat = "server"/>
<Link id = "cssStyleSheet2" rel = "stylesheet" type = "text/css" runat = "server"/>
<Link id = "cssStyleSheet3" rel = "stylesheet" type = "text/css" runat = "server"/>
</Head>

The number can only be cold ...... If you do not know how much it will be used, just put a few more. Then, the herf attribute of the <link> tag is dynamically modified on the page where MasterPage is applied. Protected void Page_Init (object sender, EventArgs e ){
If (! IsPostBack ){
HtmlLink csslink = (HtmlLink) Master. FindControl ("cssStyleSheet1 ");
Csslink. Attributes. Add ("href", "Cart.css ");
}
}

At present, I have discovered only these two methods. If you have any good solutions, please tell your younger brother that you are currently working on an application involving this problem.

PS. Is there a bug in garden? I suddenly found out that I got to the homepage ...... It seems to have been sent to another category. If you edit the default category, the homepage will be changed ...... -_-Bb

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.