Reputation: 21
I'm using asp:menu
for showing the menus in masterpage. If I click the menu item 1, the corresponding page is loading in the content page. I need that the selected menu item should be highlighted with some color. Please help me out.
Menu code is as follows:
<asp:menu id="NavigationMenu"
staticsubmenuindent="10px"
orientation="Horizontal"
runat="server" BackColor="#E3EAEB" DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#666666">
<items>
<asp:menuitem text="Home" Value="Home" NavigateUrl="~/page1.aspx"></asp:menuitem>
<asp:MenuItem NavigateUrl="~/page2.aspx" Text="About" value="About"></asp:MenuItem>
<asp:MenuItem NavigateUrl="~/page1.aspx" Text="Contact" Value="Contact"></asp:MenuItem>
</items>
<StaticSelectedStyle BackColor="#1C5E55" />
<StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<DynamicHoverStyle BackColor="#666666" ForeColor="White" />
<DynamicMenuStyle BackColor="#E3EAEB" />
<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<StaticHoverStyle BackColor="#666666" ForeColor="White" />
<StaticItemTemplate>
<%# Eval("Text") %>
</StaticItemTemplate>
</asp:menu>
Upvotes: 2
Views: 7677
Reputation: 3338
You can use something like the to select (and ultimately highlight) the active menu item.
protected void Page_Load(object sender, EventArgs e)
{
foreach (MenuItem item in Menu1.Items)
{
if (Path.GetFileName(item.NavigateUrl).Equals(
Path.GetFileName(Request.PhysicalPath),
StringComparison.InvariantCultureIgnoreCase))
{
item.Selected = true;
}
}
}
Upvotes: 3
Reputation: 1340
You should create a .sitemap and bind your menu to the sitemap. The following link has a decent overview of using sitemaps with menus as well as how to enable security trimming for your menu.
Upvotes: 1