Click here to Skip to main content
15,908,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need server side code to change the ASP.Net selected menu background color when click the menu item.
Posted
Comments
[no name] 21-Nov-11 7:48am    
Why does it have to be server-side? This can easily be done with a single line of JavaScript on the client

1 solution

C#
protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
  {
      Menu1.BackColor = System.Drawing.Color.Black;
  }
 
Share this answer
 
Comments
Robymon 21-Nov-11 8:00am    
This code is not working. This is my code, Please check anything wrong in the code, Menu is in the Masterpage.

HTML Code
----------

<asp:Menu ID="Menu1" runat="server" Orientation="Vertical" StaticMenuItemStyle-CssClass="menuItem"
DynamicMenuItemStyle-CssClass="menuItem" StaticHoverStyle-CssClass="menuItemOver"
DynamicHoverStyle-CssClass="menuItemOver"
OnMenuItemClick="Menu1_MenuItemClick">
<staticmenuitemstyle cssclass="menuItem">
<dynamichoverstyle cssclass="menuItemOver">
<dynamicmenuitemstyle cssclass="menuItem">
<statichoverstyle cssclass="menuItemOver">



Server Side Code
----------------

protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
{
Menu1.BackColor = System.Drawing.Color.Red;
Response.Redirect(e.Item.Target);
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900