INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Jobs from Indeed

Using two css files within a master page

Using two css files within a master page

(OP)
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

RE: Using two css files within a master page

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.

RE: Using two css files within a master page

(OP)
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>





RE: Using two css files within a master page

(OP)
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 ?

RE: Using two css files within a master page

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 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close