Accessing Site Map Information Programmatically
If you are not using a SiteMapPath control, you can still programmatically access site map information through the Site Map API (found in the System.Web.SiteMap namespace). The following code segment shows how to display site navigation information programmatically:
 | |
| Figure 13. Changing Orientation: In this screen shot the orientation of the Menu control has been changed to vertical. Compare with the horizontal orientation in Figure 12 to see the difference. |
Partial Class MasterPage_master
Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles Me.Load
Dim myCurrentNode As SiteMapNode
'---Gets the current node
myCurrentNode = SiteMap.CurrentNode
'---displays the navigational path---
Dim path As String = myCurrentNode.Title
While myCurrentNode.ParentNode IsNot Nothing
myCurrentNode = myCurrentNode.ParentNode
path = " > " & path
path = myCurrentNode.Title & path
End While
Response.Write(path)
End Sub
End Class
Besides the
CurrentNode property, you can also access site information using:
- SiteMap.CurrentNode.ParentNode
- SiteMap.CurrentNode.PreviousSibling
- SiteMap.CurrentNode.RootNode
- SiteMap.CurrentNode.NextSibling
In this article, you have seen the various new controls in ASP.NET 2.0 that support site navigation. Site navigation is an important feature of user-friendly Web sites. And having a variety of ways to represent the navigation will allow you to choose the one that best fits the content and the user needs of your site. Remember, a Web site with lots of information is useless without a good navigational mechanism to let users find what they need. Be sure to take plenty of time to experiment with these important new controls and think about how best to apply them in your site.