Search code examples
c#asp.net.netmaster-pagespage-title

how to change title of aspx page dynamically on page load


I had set of ASPX pages in which each page had different titles, but I want to put default title for pages which don't have a title. The default title must be configurable.


Solution

  • If this is classic ASP.NET (not MVC) and you are using MasterPage then you can set default title in Page_Load event in MasterPage:

    protected void Page_Load(object sender, EventArgs e)
    {
          if (string.IsNullOrEmpty(Page.Title))
          {
               Page.Title = ConfigurationManager.AppSettings["DefaultTitle"];  //title saved in web.config
          }
    }