Links css file to content page

I have a Master page and some content pages.
I want to assign a different css file to each of the content pages.

(without using themes)
How can I do this?

+2


source to share


4 answers


I did it once by adding a placeholder title on the master page and explicitly specifying the css in the content pages.

In the Master:

<head runat="server">
    <title></title>
    <link href="~/css/common.css" rel="stylesheet" type="text/css" />
    <!-- loads of other stuff / -->
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>

      



and in content:

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
        <link href="../css/SomeContent.css" rel="stylesheet" type="text/css" />
        <script src="../js/SomeJsToo.js" type="text/javascript"></script>
</asp:Content>

      

+5


source


If you are using visual studio 2008 you will have a very simple time. First, create your master page like this:

    <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">

        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>

      

Now create a content page on that master page:



    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
</asp:Content>

      

Now, in the Content1 placeholder, you simply place the stylesheet that you would like to apply to this page.

What is it. Hope this works for you.

+1


source


Use an external master CSS file for all pages using:

<link rel="stylesheet" type="text/css" href="master.css" />

      

Then you can use inline CSS on individual content pages using a style tag like:

<style type="text/css">
h1 {color:red}
p {color:blue}
</style>

      

0


source


I've tried many of the above methods but still get the error. Finally, I am using the following codes on page load and it works great:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim css1 As New HtmlLink
    css1.Href = ResolveUrl("report.css")
    css1.Attributes("rel") = "stylesheet"
    css1.Attributes("type") = "text/css"
    css1.Attributes("media") = "all"
    Me.Page.Header.Controls.Add(css1)

End Sub

      

0


source







All Articles