How can I control and change the contents within the <head> section of the master page? I'm using nested master pages, and I need to specify a different stylesheet for the nested master page. How can I accomplish this?
Master Page:
<%@ Master Language="C#" %>
<%@ Register Src="../UserControls/TopNa
vigationBa
r.ascx" TagName="TopNavigationBar"
TagPrefix="uc2" %>
<%@ Register Src="../UserControls/searc
hform.ascx
" TagName="searchform" TagPrefix="uc1" %>
<%@ Register Src="../UserControls/MainN
avigationB
ar.ascx" TagName="MainNavigationBar
" TagPrefix="uc3" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml"
>
<head id="Head1" runat="server">
<title>Educational Software Solutions - Student, Curriculum Assessment & Management :: CompassLearning</title>
<link href="../styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="Form1" runat="server">
<div id="container">
etc...
Nested Master Page:
<%@ Master Language="C#" MasterPageFile="~/Template
s/SiteMast
er.master"
AutoEventWireup="true" CodeFile="TwoColumnMaster.
master.cs"
Inherits="TwoColumnMaster"
%>
<%@ Register Src="../UserControls/LeftN
avigationB
ar.ascx" TagName="LeftNavigationBar
" TagPrefix="uc1" %>
<asp:content ID="Content1" ContentPlaceHolderID="Main
Content" runat="server">
<div id="leftcolumn">
<asp:ContentPlaceHolder id="LeftColumn" Runat="Server" />
<uc1:LeftNavigationBar ID="LeftNavigationBar1" runat="server" />
</div>
<div id="rightcolumn">
<asp:ContentPlaceHolder id="RightColumn" Runat="Server" />
</div>
</asp:content>
I originally tried changing the stylesheet in the content page:
public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Master.FindControl("MainNa
vigationBa
r1").Visib
le = false;
HtmlLink cssLink = new HtmlLink();
cssLink.Href = "~/styles2.css";
cssLink.Attributes.Add("re
l", "stylesheet");
cssLink.Attributes.Add("ty
pe", "text/css");
Header.Controls.Add(cssLin
k);
}
}
That just added another stylesheet reference and didn't replace the master page stylesheet reference.
I've read several articles to no avail.
Can anyone help on how to achieve this?