Dynamic | page
In the foreigner's station sees solves the good method, therefore simple compiles:
In a asp.net application, often to dynamically modify the title of the page, a typical example is, in a page navigation control, want to select which connection users, in the title of the page to display the relevant content, for example, a website, like the following Web site architecture:
There are books classification, the following there are Chinese books, foreign books classification, you can generally use the tree or ASP.net 2.0 of the newly added navigation bar control
(sitemap), to implement, for example
Book---> Chinese books;
Books----> Foreign books
And so on, and if this time, can be in the page <title> part, also can show such as "book--> Chinese book" So, that more intuitive obvious,
In asp.net 2.0, we can use the
You can then change the title of the Page_Load event in the following form, such as
Page.Header.Title = "The current time is:" & DateTime.Now.ToString ()
, you can simply write Page.title.
We can then combine it with the Sitemap control in such a way that it is implemented as follows:
Const Default_unnamed_page_title as String = "Untitled PAGE"
Const Default_page_title as String = "Welcome to my website!!"
Protected Sub Page_Load (ByVal sender as Object, ByVal e as System.EventArgs) H Andles me.load
' Set the page ' s title, if needed
If string.isnullorempty (page.title) OrElse page.title = Default_unnamed_page_title Then
& nbsp; If Sitemap.currentnode is nothing Then
Page.title = Default_page_ TITLE
Else
Page.title = getpagetitlebasedonsitenavigation ()
' Can also use the following if you ' d rather
' Page.title = getpagetitlebasedonsitenavigationusingrecursion (Sitemap.currentnode)
End If
End If
End Sub
Private Function getpagetitlebasedonsitenavigation () as String
If Sitemap.currentnode is nothing Then
Throw New ArgumentException ("CurrentNode cannot is nothing")
End If
' We are visiting a page defined in the site Map-build up the page title
' Based on the site map node ' hierarchy
Dim output as String = String.Empty
Dim CurrentNode as SiteMapNode = Sitemap.currentnode
While CurrentNode IsNot nothing
If output. Length > 0 Then
Output = Currentnode.title & "::" & Output
Else
Output = Currentnode.title
End If
CurrentNode = Currentnode.parentnode
End While
Return output
End Function
In the above code, first predefined two constants, and then gradually set up the Sitemap node, the first node is null, and then call the
Getpagetitlebasedonsitenavigation () This process, in each building a sitemap node, with a string to connect, and finally return to Page.title can be implemented, of course, can also be implemented recursively