6

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 2

14

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>
Sign up to request clarification or add additional context in comments.

2 Comments

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/…
this is a really neat solution, +1
4

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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.