Friday, October 17, 2008

ASP.Net Menucontrol Selected Property

When you are using the menu control in a Master page and you navigate to a new page the Selected value properties of the menu control are lost and do not display. In VB the code to rectify this is as follows:

Found this link written in C# which helped:
http://www.eggheadcafe.com/community/aspnet/17/10028397/highlighting-the-menu-sel.aspx

In the Page_Load section
Dim ThisPage As String = Page.AppRelativeVirtualPath

For Each parentMenu As MenuItem In Menu1.Items
If parentMenu.NavigateUrl = ThisPage Then
parentMenu.Selected = True
Else
For Each childMenu As MenuItem In parentMenu.ChildItems
If childMenu.NavigateUrl = ThisPage Then
childMenu.Selected = True
childMenu.Selectable = False
End If
Next
End If
Next

No comments:

Post a Comment