0

Hi

I have a menu in a master page.

<asp:Menu  Width="320" Orientation="Horizontal" ID="mnuAdd" runat="server">
<StaticMenuItemStyle CssClass="staticTabs" />
<StaticHoverStyle CssClass="hoverTabs" />
<StaticSelectedStyle CssClass="selectedTabs" />
<Items>
<asp:MenuItem  Text="Test1"  NavigateUrl ="~/Test1.aspx" />
<asp:MenuItem Text="Test2" NavigateUrl="~/Test2.aspx" /> 
<asp:MenuItem Text="Test3" NavigateUrl="~/Test3.aspx" />
<asp:MenuItem  Text="Test4" NavigateUrl="~/Test4.aspx" />
</Items>
</asp:Menu>

But when I select a menuitem, the forecolor or backcolor doesn't change for the selected menuitem. I have googled all day and I thought I found someting that would work, but I haven't got it to work. I have this Page_Load in the file MasterPage.master.vb

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim ThisPage As String = Page.AppRelativeVirtualPath
        Dim ParentMenu As MenuItem
        For Each ParentMenu In mnuAdd.Items
            If ParentMenu.NavigateUrl = ThisPage Then
                ParentMenu.Selected = True
            End If
        Next
    End Sub

But nothing happens with the selected menuitem.

I also saw that I should use sitemap. But when I added that the menu wasn't horizontal any more. And I rather don't want to use sitemap. Because I wan't to add the menuitems dynamically. I have already tried that but that didn't help me with StaticSelectedStyle problem.

Protected Sub AddMenu()
        Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("connectionString").ConnectionString)

        Try

            If con.State = ConnectionState.Closed Then
                con.Open()
            End If
            Dim cmd As SqlCommand = New SqlCommand("spAddMenu", con)
            cmd.CommandType = CommandType.StoredProcedure
            Dim r As SqlDataReader = cmd.ExecuteReader()
          
                While (r.Read())
                Dim mi As MenuItem = New MenuItem()
                mi.Text = r(1).ToString()
                mi.Value = r(2).ToString
                mnuAdd.Items.Add(mi)

            End While
             r.Close()

        Catch e As Exception
        Finally

            con.Close()
        End Try


    End Sub

I called the AddMenu in Page_Load if not IsPostBack. But nothing helps.

Please help me
Fia

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Heena Chavda
0

This works for me. It's in C# but the VB would be very similar.

protected void Page_Load(object sender, EventArgs e)
{
    string path = Request.AppRelativeCurrentExecutionFilePath;
    foreach (MenuItem item in NavigationMenu.Items)
    {
         item.Selected = item.NavigateUrl.Equals(path, StringComparison.InvariantCultureIgnoreCase);
     }
}
0

Hello,
This will work on IE but on mozilla the content page comes beside the page. page formatting will disturb.

I want help on this...anyone who can help me out...thanx in advance
thanx
Heena

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.