Home > .NET, asp.net, aspx, masterpage, title, web form > Set MasterPage (.master) title from a web form (.aspx)

Set MasterPage (.master) title from a web form (.aspx)

February 22nd, 2008

Lots of people complain about not being able to change the master page’s title using ASP.NET 2.0 and up. A commonly seen tutorial is to use the following piece of code:

((HtmlTitle) Page.Master.FindControl("lblTitle")).Text =
    "Set some kind of title";

In most of the cases you need to change the master page’s title, you do not have to bother about this. Just use the correct page stadium and set the page’s title. The only page event to be able to do this is Page_PreInit (since master page and content page are still separate ‘pages’ in this stadium). The following will work (if you have AutoEventWireup enabled Set MasterPage (.master) title from a web form (.aspx) icon wink ):

protected void Page_PreInit(object sender, EventArgs e)
{
    Title = "Set some kind of title";
}
If you like this blog post, you can easily share it:
  • Set MasterPage (.master) title from a web form (.aspx) services sprite
  • Set MasterPage (.master) title from a web form (.aspx) services sprite
  • Set MasterPage (.master) title from a web form (.aspx) services sprite
  • Set MasterPage (.master) title from a web form (.aspx) services sprite
  • Set MasterPage (.master) title from a web form (.aspx) services sprite
  • Set MasterPage (.master) title from a web form (.aspx) services sprite
  • Set MasterPage (.master) title from a web form (.aspx) services sprite
  • Set MasterPage (.master) title from a web form (.aspx) services sprite
Comments are closed.