How can I add a css file to only a child page while using ASP.NET master pages rather then specifying them in the master?
2 Answers
In the master page
<head>
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
In the specific page
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<link href="~/pagecssfile.css" rel="stylesheet" type="text/css" />
</asp:Content>
2 Comments
Trajan
this one is actually a lot better since the <link> tag must be in the <head> part, for quick-rendering and w3c-compatibility reasons. Read more here : stackoverflow.com/questions/1642212/…
benscabbia
this is a really neat solution, +1
You can specify it in child page inside the content as mentioned below
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<link href="Css/main.css" rel="stylesheet" type="text/css" />
scope of this css will remain for this page only
1 Comment
Trajan
references to css and js files should all be in the <head> section so they're loaded before the body is. Adrian Iftode's way is more w3c-compliant and more efficient.