dani
dani

Reputation: 1077

Links css file to a content page

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

(without using themes)
How can I do that?

Upvotes: 2

Views: 9607

Answers (4)

Parwaze
Parwaze

Reputation: 1

I have tried many of the above ways but still getting error. Finally i use the following codes on the page load and it works fine:

    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

Upvotes: 0

Nils
Nils

Reputation: 9941

I did that once by adding a header-placeholder in 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 the 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>

Upvotes: 5

Chris
Chris

Reputation: 6325

If you're using visual studio 2008, you're going to have a real easy time. First make a 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 make a content page based off of this 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 just place the stylesheet that you would like to have applied to that page.

That's it. Hope this works for you.

Upvotes: 1

James Goodwin
James Goodwin

Reputation: 7406

Use an external master CSS file for all pages using:

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

Then you can use embedded CSS on the individual content pages using the style tag, e.g:

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

Upvotes: 0

Related Questions