asp.NET - Problems with Static Selected Style for a Selected Page on the menu

后端 未结 1 471
长情又很酷
长情又很酷 2020-12-16 07:14

I am using asp.NET 4.0 with C# and have recently created a custom design for my local web application. I would like that when a page is selected, it has a different backgrou

相关标签:
1条回答
  • 2020-12-16 07:58

    This seems to be a bug with the .NET menu. There is some information regarding this here. What you might want to do then is remove the staticSelectedStyle attribute and simply add this to your css:

    .menu a.static.selected
    {
        background-color: #680840 !important;
        color: #FFF !important;
        text-decoration: none !important;
    }
    

    You might also have to add some code to your master's page load to determine which should be the selected item like this:

    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 讨论(0)
提交回复
热议问题