Jun 11
7
Changing ShowStartNode or StartNodeOffset For Sitemap In Code Behind
Sometimes you may want to change the ShowStartNode or StartNodeOffset for your sitemap file when the page is loaded in vb.net. One example is if you are using the web.sitemap file to display an asp:menu on your page. There may be certain pages that you want to show from the starting node and other times you do not.
To do this, you must place the code in under your Page_Init because it will get loaded to late if you put it in Page_Load. Here is a quick example.
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
Dim myPage As String = System.IO.Path.GetFileName(System.Web.HttpContext.Current.Request.Url.AbsolutePath)
If myPage = "Default.aspx" Then
SiteMapDataSource1.ShowStartingNode = "False"
SiteMapDataSource1.StartingNodeOffset = 2
Else
SiteMapDataSource1.ShowStartingNode = "False"
SiteMapDataSource1.StartingNodeOffset = 1
End IfEnd Sub