Keep selected menu item with another color

1

Good you can help me, I have the following menu on a master page:

<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
<Items>
<asp:MenuItem NavigateUrl="~/Catalogo.aspx" Text="HOME"/>
<asp:MenuItem NavigateUrl="~/Catalogo.aspx" Text="CATALOGO DE PRODUCTOS"/>
<asp:MenuItem NavigateUrl="~/listacomprados.aspx" Text="DETALLE DE COMPRA"/>
<asp:MenuItem NavigateUrl="#" Text="ACERCA DE"/>
<asp:MenuItem Text="CERRAR SESION"/>
<asp:MenuItem Text="PRUEBA" />

</Items>

I want that when selecting a item for example "PROOF" it takes me to another page, but I want the item "PROOF" to be kept with another color in the background. Greetings and thanks.

If you look at this same page when you select item "Ask a question" the item stays with another color. It is exactly what I want to do.

    
asked by Yehudy 22.02.2017 в 19:19
source

1 answer

1

I recommend that you delete the properties EnableViewState and IncludeStyleBlock and add StaticSelectedStyle in the menu, leaving this way your aspx:

<asp:Menu ID="NavigationMenu" runat="server" Orientation="Horizontal">
    <StaticSelectedStyle BackColor="Red" />
    <Items>
        <asp:MenuItem NavigateUrl="~/Catalogo.aspx"  Text="HOME"/>
        <asp:MenuItem NavigateUrl="~/Catalogo.aspx" Text="CATALOGO DE PRODUCTOS"/>
        <asp:MenuItem NavigateUrl="~/listacomprados.aspx" Text="DETALLE DE COMPRA"/>
        <asp:MenuItem NavigateUrl="#" Text="ACERCA DE"/>
        <asp:MenuItem Text="CERRAR SESION"/>
        <asp:MenuItem Text="PRUEBA"  />

        <%--<asp:MenuItem NavigateUrl="~/inicio.aspx" Text="CERRAR SESION"/>--%>
    </Items>
</asp:Menu>

And also, you add the following code in Page_Load of Visual Basic :

Try
    For Each m As MenuItem In NavigationMenu.Items
        Dim path As String = HttpContext.Current.Request.Url.AbsolutePath + ".aspx"
        Dim words As String() = m.NavigateUrl.Split(New Char() {"/"c})
        Dim words2 As String() = path.Split(New Char() {"/"c})

        If words(1).ToString().Equals(words2(1).ToString()) Then
            m.Selected = True
        End If
    Next
Catch
End Try
    
answered by 22.02.2017 / 22:53
source