A simple and convenient mechanism for solving the net2.0 of page headers was recently SiteMapPath when using the page navigation component of Ms.
The current problems:
First, the entire site ASPX page title usually does not have a unified location, for each page or directly hard-coded page title in the page of the ASPX file, or through Aspx.cs dynamic write in (1.1 also add additional title control, 2.0 can use the Page.title property , and the entire site if a lot of words, this repetitive logic code will be written many times, extremely unattractive, and can not be used in other places to achieve the title information synchronization.
Even if all the page headers are placed in a resource (or XML) file to support multilanguage support, there is also a problem with using the program code to load headers, that is, where the page title is used in the page, it may not only be in the title area (page navigation control), but also how to get those controls from these resource files ( or XML) to get these header information is also a headache problem.
The purpose to be achieved:
First, in the main template throughout the site to solve all the problems of the title of the page, all the titles used in all sites are placed in the Web.sitemap (multilingual) to maintain, so you can simultaneously maintain the navigation information of the page.
Second, in the pop-up form of the title automatically for each site after the title added site name (User login | seven-Si software), but in the page navigation control to refer to the title when the site name does not appear, such as (Home > member Center > User login).
When referencing the Page.title property in a aspx.cs program, you cannot have the site name as shown in the title bar of the page (user login | seven-Si software), but the Page.title value referenced in the normal program of the page is (user login).
The specific implementation methods are as follows:
Add the following code to the masterpage of the Web site:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.searchDescription.Content = this.SearchDescription;
this.searchKeywords.Content = this.SearchKeywords;
}
if (SiteMap.CurrentNode != null)
{
this.Page.Title = SiteMap.CurrentNode.Title;
}
else
{
this.Page.Title = "尚未在Web.sitemap配置此页面导航";
}
}
protected override void Render(HtmlTextWriter writer)
{
this.Page.Title = this.Page.Title + " | " + Keyss.WebFramework.ConfigManager.GetInstance().SiteName;
base.Render(writer);
}
Explain:
One, the reason is not (!this. IsPostBack) {} block is implemented because page. The view state cannot be saved in title, which I think is a small bug in the. net2.0.
Second, the reason for overriding the title property in the Render method is that the Render method does not save ViewState while the page is in its lifetime, but from the write page. The title content is valid only in MasterPage because MasterPage is responsible for the render of the title of the page, in the Render method of the next page, title has been render completed, some time change title does not affect the result of the render.