Επεξεργασία

Κοινή χρήση μέσω


Menu.StaticSelectedStyle Property

Definition

Gets a reference to the MenuItemStyle object that allows you to set the appearance of the menu item selected by the user in a static menu.

public:
 property System::Web::UI::WebControls::MenuItemStyle ^ StaticSelectedStyle { System::Web::UI::WebControls::MenuItemStyle ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public System.Web.UI.WebControls.MenuItemStyle StaticSelectedStyle { get; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.StaticSelectedStyle : System.Web.UI.WebControls.MenuItemStyle
Public ReadOnly Property StaticSelectedStyle As MenuItemStyle

Property Value

A reference to the MenuItemStyle that represents the style of the selected menu item in a static menu.

Attributes

Examples

The following code example demonstrates how to use the StaticSelectedStyle property to specify a light blue background color for the selected static menu item.


<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>Menu StaticSelectedStyle Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>Menu StaticSelectedStyle Example</h3>
    
      <asp:menu id="NavigationMenu"
        staticdisplaylevels="2"
        staticsubmenuindent="10" 
        orientation="Vertical"
        runat="server">
        
        <staticselectedstyle backcolor="LightBlue"
          borderstyle="Solid"
          bordercolor="Black"
          borderwidth="1"/>
      
        <items>
          <asp:menuitem text="Home"
            tooltip="Home">
            <asp:menuitem text="Music"
              tooltip="Music">
              <asp:menuitem text="Classical"
                tooltip="Classical"/>
              <asp:menuitem text="Rock"
                tooltip="Rock"/>
              <asp:menuitem text="Jazz"
                tooltip="Jazz"/>
            </asp:menuitem>
            <asp:menuitem text="Movies"
              tooltip="Movies">
              <asp:menuitem text="Action"
                tooltip="Action"/>
              <asp:menuitem text="Drama"
                tooltip="Drama"/>
              <asp:menuitem text="Musical"
                tooltip="Musical"/>
            </asp:menuitem>
          </asp:menuitem>
        </items>
      
      </asp:menu>

    </form>
  </body>
</html>

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>Menu StaticSelectedStyle Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>Menu StaticSelectedStyle Example</h3>
    
      <asp:menu id="NavigationMenu"
        staticdisplaylevels="2"
        staticsubmenuindent="10" 
        orientation="Vertical"
        runat="server">
        
        <staticselectedstyle backcolor="LightBlue"
          borderstyle="Solid"
          bordercolor="Black"
          borderwidth="1"/>
      
        <items>
          <asp:menuitem text="Home"
            tooltip="Home">
            <asp:menuitem text="Music"
              tooltip="Music">
              <asp:menuitem text="Classical"
                tooltip="Classical"/>
              <asp:menuitem text="Rock"
                tooltip="Rock"/>
              <asp:menuitem text="Jazz"
                tooltip="Jazz"/>
            </asp:menuitem>
            <asp:menuitem text="Movies"
              tooltip="Movies">
              <asp:menuitem text="Action"
                tooltip="Action"/>
              <asp:menuitem text="Drama"
                tooltip="Drama"/>
              <asp:menuitem text="Musical"
                tooltip="Musical"/>
            </asp:menuitem>
          </asp:menuitem>
        </items>
      
      </asp:menu>

    </form>
  </body>
</html>

Remarks

Use the StaticSelectedStyle property to control the appearance of the menu item selected by the user in a static menu. This property is read-only; however, you can set the properties of the MenuItemStyle object it returns. The properties can be set declaratively in the form Property-Subproperty, where Subproperty is a property of the MenuItemStyle object (for example, StaticSelectedStyle-ForeColor). The properties can also be set programmatically in the form Property.Subproperty (for example, StaticSelectedStyle.ForeColor).

Style properties for a static menu item are applied in the following order:

  1. StaticMenuStyle.

  2. StaticMenuItemStyle. If the LevelMenuItemStyles collection or LevelSubMenuStyles collection is defined, it is applied at this time, overriding the other menu item style properties.

  3. StaticSelectedStyle. If the LevelSelectedStyles collection is defined, it is applied at this time, overriding the other menu item style properties.

  4. StaticHoverStyle.

Important

Breaking change below.

Before .NET Framework 4.0, when defining an <asp:Menu> control in the .aspx file, users can set the StaticSelectedStyle-CssClass property to set the CSS class of the selected control item. For example, user may have a menu control as below:

<asp:Menu ID="Menu1" runat="server" Orientation="Horizontal"   
    StaticMenuItemStyle-CssClass="MenuItem"  
    StaticSelectedStyle-CssClass="MenuItem_selected"  
    OnMenuItemClick="Menu1_MenuItemClick" Style="margin-bottom: 0px" EnableTheming="True" ClientIDMode="Static">  
    <Items>  
        <asp:MenuItem Text="item_0" Value="0" Selected="True"></asp:MenuItem>  
        <asp:MenuItem Text="itme_1" Value="1"></asp:MenuItem>  
    </Items>  
</asp:Menu>  

And the menu control is rendered as:

<div id="Menu1" style="margin-bottom: 0px">  
    <ul class="level1">  
        <li><a class="level1 MenuItem MenuItem_selected " href="#" onclick="__doPostBack(&#39;Menu1&#39;,&#39;0&#39;)">item_0</a></li>  
        <li><a class="level1 MenuItem" href="#" onclick="__doPostBack(&#39;Menu1&#39;,&#39;1&#39;)">itme_1</a></li>  
    </ul>  
</div>  

However, in .NET Framework 4.0 and later, the selected menu item is set to the selected CSS class always instead of the class specified by StaticSelectedStyle-CssClass. Therefore, the above ASP.NET code is rendered instead as:

<div id="Menu1" style="margin-bottom: 0px">  
    <ul class="level1">  
        <li><a class="level1 MenuItem selected " href="#" onclick="__doPostBack(&#39;Menu1&#39;,&#39;0&#39;)">item_0</a></li>  
        <li><a class="level1 MenuItem" href="#" onclick="__doPostBack(&#39;Menu1&#39;,&#39;1&#39;)">itme_1</a></li>  
    </ul>  
</div>  

Applies to

See also