The Muffin Man
The Muffin Man

Reputation: 20004

Problem setting page title in content page when title is set in master page

I have a master page and in its page load event I am appending to the page title:

Title = Title + " MyWebsite";

Then in a page that uses the previous master page:

Title = "Home";

What ends up rendering is the value from the master page. A closer look at the debugger shows that it evaluates the Title attribute in my content page, but still says it's an empty string (even though I explicitly have a value set to it.)

Note: Content pages get evaluated before master pages ( I didn't realize this).

Upvotes: 1

Views: 1244

Answers (2)

Muhammad Akhtar
Muhammad Akhtar

Reputation: 52241

You need to set page title in Page_PreInit event

protected void Page_PreInit(object sender, EventArgs e)
{  
  //set here....
}

Upvotes: 3

Rahul Soni
Rahul Soni

Reputation: 4968

I have used the following... and it works as expected.

this.Page.Title = this.Page.Title + " Master Title";

Upvotes: 0

Related Questions