views:

97

answers:

2

I have a MasterPage, several content pages - each of the content pages have a UserControl.

In the MasterPage, I'm setting the Page.Title programmatically based on Page_Init "Request.UserAgent.Contains....", so that the content pages end up with different page titles based on this.

Each content page has its Title set to blank (Title=" "), but when the page renders, the pragmatically generated page title shows up in the browser tab.

In the UserControl code behind, I need to access the content page's (parent page) Page.Title value, and base on this, display some text:

If(Page.Title == "something") 
{
Lable.Text = "something"; 
} 
else if (Page.Title == "somethingElse")
{
lable.Text = "somethingElse";
}

However, my label remains blank when using this code. What is the way I need to determine the current Page.Title to what the MasterPage has set it as?

C# Please

A: 
    If(this.Parent.Page.Title == "something") 
    {
        Label.Text = "something"; 
    } 
        else if (this.Parent.Page.Title == "somethingElse")
    {
        label.Text = "somethingElse";
    }

you can also use this.Master.Page.Title if you are ALWAYS setting the title in the masterpage.

Also, remember that every page as a Life Cycle. If you are checking for the title before the title is set, then it will return a blank string.

To test the code, try hard-coding a title in the master page and see if your code is working. Once you know the code is in fact pulling the title from the parent, then you need to make sure that you are setting the page title BEFORE you try and poll for it.

rockinthesixstring
Hi rockinthesixstring, still getting blank title. Any other ideas? Thanks, Doug
Doug
please see my edit. You need to look into a page life cycle | http://msdn.microsoft.com/en-us/library/ms178472.aspx
rockinthesixstring
Thank again, took a look at your life cycle link. I made a change t my Master page code, and also used this.Master.Page.Title. Everything's working now. The Life Cylce link was helpfull too.
Doug
awesome, glad I could help!
rockinthesixstring
A: 

this.Master.Page.Title should give you the Master Page's title which you can test and set to whatever you like.

this.Parent.Page.Title just gives you the Page's parent control which isn't necessarily the Master.

Eric H