Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using two css files within a master page 1

Status
Not open for further replies.

dvannoy

MIS
May 4, 2001
2,765
US
I'm trying to use two different css styles in my master page. both files are exactly the same except one expands the form wider.

In my master page I have the following;

<head runat="server">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title></title>
<link rel="stylesheet" href="SiteStyles/MasterPage.css" type="text/css" />
<link rel="stylesheet" href="SiteStyles/MasterPageExtended.css" type="text/css" />
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>

</head>

In my form if I specify which css to point to it doesn't work. it just uses the last entry in my master page which is <link rel="stylesheet" href="SiteStyles/MasterPageExtended.css" type="text/css" />

in my form I'm specifying the css location as follows;
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<link rel="stylesheet" href="SiteStyles/MasterPage.css" type="text/css" />
</asp:Content>


What am I doing wrong ?

any help would be appreciated

Thanks
 
I am not sure what you are trying to do. I think you are confused on how the style sheets are used.
You are including 2 style sheets on your master page. Those will be included on EVERY page that uses that masterpage.
By adding a link to the style sheet on your page, you are not "telling" the master page to use that style sheet, you are just including on the page again.

Your master page should only include style sheets that you want to affect every page with that uses it. If you need other styles on a specific page, but don't want to affect all the others, then include that style sheet on your page.
 
I want all pages to use <link rel="stylesheet" href="SiteStyles/MasterPage.css" type="text/css" /> unless I specify the page to use <link rel="stylesheet" href="SiteStyles/MasterPageExtended.css" type="text/css" />

all pages are content pages of my master page(only one master page). so every page would inherit <link rel="stylesheet" href="SiteStyles/MasterPage.css" type="text/css" />

now how can I force a content page to use <link rel="stylesheet" href="SiteStyles/MasterPageExtended.css" type="text/css" /> ??

here is a mark up of a content page

<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="About.aspx.vb" Inherits="MySite.About" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<link rel="stylesheet" href="SiteStyles/MasterPageExtended.css" type="text/css" />
</asp:Content>





 
I was able to get it to work using <link href='<%= ResolveClientUrl("~/SiteStyles/MasterPageExtended.css") %>' rel="stylesheet" type="text/css"/> in the ContentPlaceHolderID="HeadContent" of my content page.

is this the correct to handle this ?
 
I would do it this way:
Create a public property on your master page. It can be of type string or a list of strings. You can set the default value to be "MasterPage.css"

Then from any page in your site, you can set that property to "MasterPageExtended.css" or any other style sheet or sheets.

In the code behind of the master page, you can check if value of that property and manually add the stylesheet to the head of the page.

You can then create a new htmllink and add it to the header
Code:
 Dim link As New HtmlLink
        link.Href = url
        link.ID = id
        link.Attributes.Add("type", "text/css")
        link.Attributes.Add("rel", "stylesheet")
        Header.Controls.Add(link) -- use the id of your header
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top