Solved

nested master pages help

Posted on 2006-07-23
2
249 Views
Last Modified: 2012-06-21
I'm using nested master pages and I need to override the header content so that I can reference a different style sheet for my nested master page, as well as, change the title for my content pages.  I was trying an object oriented approach.

Here is the header section of my main master page:

<%@ Master Language="C#" %>
<%@ Register Src="../UserControls/TopNavigationBar.ascx" TagName="TopNavigationBar"
    TagPrefix="uc2" %>
<%@ Register Src="../UserControls/searchform.ascx" TagName="searchform" TagPrefix="uc1" %>
<%@ Register Src="../UserControls/MainNavigationBar.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><% = m_HtmlTitle %></title>
    <link href="../<% = m_HtmlStyles %>" rel="stylesheet" type="text/css" />
</head>
<body>
etc., etc...

Here is tMain master code-behind:

public partial class Template : System.Web.UI.MasterPage
{
    protected String m_HtmlTitle;

        public String HtmlTitle
        {
            get { return m_HtmlTitle; }
            set { m_HtmlTitle = value; }
        }

        protected String m_HtmlStyles;

        public String HtmlStyles
        {
            get { return m_HtmlStyles; }
            set { m_HtmlStyles = value; }
        }

    protected void Page_Load(object sender, EventArgs e)
    {
             this.Master.HtmlTitle = "Educational Software Solutions - Student, Curriculum Assessment & Management :: CompassLearning";
             this.Master.HtmlStyles = "styles.css";
    }
}


I'm getting the following error:

The name 'm_HtmlTitle' does not exist in the current context

Any help is appreciated.


0
Comment
Question by:-Dman100-
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 7

Accepted Solution

by:
pradeepsudharsan earned 500 total points
ID: 17166177
0
 

Author Comment

by:-Dman100-
ID: 17168659
I read the articles and tried using:

public partial class index : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Master.FindControl("MainNavigationBar1").Visible = false;

        HtmlLink cssLink = new HtmlLink();
        cssLink.Href = "~/styles2.css";
        cssLink.Attributes.Add("rel", "stylesheet");
        cssLink.Attributes.Add("type", "text/css");
        Header.Controls.Add(cssLink);
    }
}

When I ran my page, it showed that the stylesheet had been added, but I still had my original stylesheet listed.  So, my page had my original stylesheet from my master page and the new stylesheet added on the pageload.

I want to replace the stylesheet from the master page with the new one?

Since I have nested master pages, ideally, I'd like to switch the stylesheet within the nested master page.

My master page uses styles.css
My nested master page needs to use styles2.css

Possible?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question