Search code examples
asp.netvb.netmenumenuitembackcolor

Change asp.net MenuItem BackColor depending on if said MenuItem is enabled?


I'm wondering if it's possible to change the BackColor of a MenuItem based on whether or not that MenuItem is disabled.

I have certain menu items disabled, but the BackColor and ForeColor are assigned, so I have no way of telling which items are currently disabled.

<StaticMenuItemStyle BackColor="#789DC8" ForeColor="#FFFFFF"/>
<StaticHoverStyle BackColor="#81B6C5" ForeColor="#404040" />
<StaticSelectedStyle BackColor="#E7F0FA" ForeColor="#404040" />

Solution

  • Disabled menu items render in browser as

    <a ... disabled="true">.... </a>
    

    Knowing this you can target those specific item with CSS e.g. try adding following CSS to your page with menu:

    a[disabled="true"] {
       color:darkgray;
       background-color:gray;
    }
    

    This will display all disabled menu items in dark gray color on gray background