troubleshooting Question

Disable Naviagtion Link when on same aspx page.

Avatar of Robert Treadwell
Robert TreadwellFlag for United States of America asked on
ASP.NETVisual Basic.NET
3 Comments1 Solution339 ViewsLast Modified:
I am using sitemaps to control site navigation and when I am on a particular page I want to disable the link of that page.  The following code I am using to control this functionality but it is not working.  The link is still selectable.  When I load the page it sets all menu items to true.  

What am I doing wrong.  See code provided.
Site Map:

<siteMapNode url="" title="Root"  description="Root">
    <siteMapNode url="~/Default.aspx" title="Home"  description="Home" />
    <siteMapNode url="~/MemberContentPages/MemberHome.aspx" title="Member Home"  description="Member Home"/>
    <siteMapNode url="~/Account/Register.aspx" title="Add a Member"  description="Add a Member" />
    <siteMapNode url="~/Account/ChangePassword.aspx" title="Change Password"  description="Change Password" />
    <siteMapNode url="~/Account/AdminOps.aspx" title="Administration Options"  description="Administration Options" />

.aspx code
 <!--Enter Navigation Content Here-->
    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" SiteMapProvider="AccountSiteMap" ShowStartingNode="false" />    
    <div id="familyNav">
    <h2>Account Navigation</h2>
        <asp:Menu ID="AccountNavigator" Runat="server" DataSourceID="SiteMapDataSource1" OnMenuItemDataBound="navMenu_MenuItemDataBound"
        orientation="Vertical"  StaticMenuItemStyle-CssClass="familyNavMenuItem" />

vb Code:

 Protected Sub navMenu_MenuItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MenuEventArgs) Handles AccountNavigator.MenuItemDataBound
        Dim mnuItem As MenuItem = CType(e.Item, MenuItem)
        Dim strUrl As String = Request.Url.ToString.ToLower()

            If _
            (e.Item.Text = "Home" And strUrl.EndsWith("Default.aspx")) Or _
            (e.Item.Text = "Member Home" And strUrl.EndsWith("MemberHome.aspx")) Or _
            (e.Item.Text = "Add a Member" And strUrl.EndsWith("Register.aspx")) Or _
            (e.Item.Text = "Change Password" And strUrl.EndsWith("ChangePassword.aspx")) Or _
            (e.Item.Text = "Change Password" And strUrl.EndsWith("ChangePasswordSuccess.aspx")) Or _
            (e.Item.Text = "Administration Options" And strUrl.EndsWith("AdminOps.aspx")) _
                e.Item.Selectable = False
                Response.Write(e.Item.Text + " was set to False ")
                e.Item.Selectable = True
                Response.Write(e.Item.Text + " was set to True ")
            End If

        Catch ex As Exception
        End Try
    End Sub
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros