asp:Menu select based on URL
-
I am trying to select menu Items if based on url. below is my code and its not working, Please help
Dim strFilePath As String = Me.Context.Request.FilePath
If (strFilePath.Contains(strFilePath.IndexOf("/Groups.aspx").ToString)) = True Then
Menu2.Items(0).Selected = True
ElseIf (strFilePath.Contains(strFilePath.IndexOf("/Reports.aspx").ToString)) = True Then
Menu2.Items(2).Selected = True
Menu2.Items(0).Selected = False
Else : Menu2.Items(0).Selected = FalseEnd If
-
I am trying to select menu Items if based on url. below is my code and its not working, Please help
Dim strFilePath As String = Me.Context.Request.FilePath
If (strFilePath.Contains(strFilePath.IndexOf("/Groups.aspx").ToString)) = True Then
Menu2.Items(0).Selected = True
ElseIf (strFilePath.Contains(strFilePath.IndexOf("/Reports.aspx").ToString)) = True Then
Menu2.Items(2).Selected = True
Menu2.Items(0).Selected = False
Else : Menu2.Items(0).Selected = FalseEnd If
-
Here is my adjustments but it still not working
Dim strFilePath As String = Me.Context.Request.FilePath
If (strFilePath.Contains("/Groups.aspx")) = True Then
Menu2.Items(0).Enabled = True
ElseIf (strFilePath.Contains("/Reports.aspx")) = True Then
Menu2.Items(2).Enabled = True
Menu2.Items(0).Enabled = False
Else
Menu2.Items(0).Enabled = False
End If -
Here is my adjustments but it still not working
Dim strFilePath As String = Me.Context.Request.FilePath
If (strFilePath.Contains("/Groups.aspx")) = True Then
Menu2.Items(0).Enabled = True
ElseIf (strFilePath.Contains("/Reports.aspx")) = True Then
Menu2.Items(2).Enabled = True
Menu2.Items(0).Enabled = False
Else
Menu2.Items(0).Enabled = False
End If -
What does "not working" mean?
There are only 10 types of people in the world, those who understand binary and those who don't.
-
So what happens when you step through the code?
There are only 10 types of people in the world, those who understand binary and those who don't.
-
Add in some code to set the backgroundcolor of the control you're manipulating; that way you can check easily whether or not you're talking to the correct control, and whether all other code works. If it does, then there's a chance that the "enabled" property is being reset or overwritten by another part of the code.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
-
One thing to be aware of. You're doing a case sensitive comparison of a string there. What happens if the case doesn't match what you're testing for (hint, you won't trigger any of your enable conditions)?
-
I am trying to select menu Items if based on url. below is my code and its not working, Please help
Dim strFilePath As String = Me.Context.Request.FilePath
If (strFilePath.Contains(strFilePath.IndexOf("/Groups.aspx").ToString)) = True Then
Menu2.Items(0).Selected = True
ElseIf (strFilePath.Contains(strFilePath.IndexOf("/Reports.aspx").ToString)) = True Then
Menu2.Items(2).Selected = True
Menu2.Items(0).Selected = False
Else : Menu2.Items(0).Selected = FalseEnd If
put it in the PreRender funtion protected void Page_PreRender(object sender, EventArgs e) { Menu mymenu = (Menu)Form.FindControl("Menu1"); MenuItem mi = mymenu.FindItem("Programs"); mi.Selected = true; }