如何在页面加载时动态更改aspx页面的标题

问题描述:

我有一组ASPX页面,其中每个页面都有不同的标题,但是我想为没有标题的页面设置默认标题.默认标题必须是可配置的.

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.

如果这是经典的ASP.NET(不是MVC),并且您正在使用MasterPage,则可以在MasterPage中的Page_Load事件中设置默认标题. :

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
      }
}