Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets a value that indicates whether the MenuItem object can be selected, or is "clickable."
public:
property bool Selectable { bool get(); void set(bool value); };
[System.ComponentModel.Browsable(true)]
public bool Selectable { get; set; }
[<System.ComponentModel.Browsable(true)>]
member this.Selectable : bool with get, set
Public Property Selectable As Boolean
true
if the menu item can be selected; otherwise, false
.
The following example demonstrates how a menu item with the Selectable property set to false
appears and functions in a menu.
<%@ 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 Selectable and Enabled properties Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Menu Selectable and Enabled properties Example</h3>
Note that Home, set to Selectable=false, is unselectable, but still shows all child items.<br />
Movies, set to Enabled=false, is unselectable, is greyed out, and does not show child items. <br />
<asp:menu id="NavigationMenu"
staticdisplaylevels="1"
staticsubmenuindent="10"
orientation="Vertical"
target="_blank"
runat="server">
<dynamicmenustyle backcolor="LightSkyBlue"
forecolor="Black"
borderstyle="Solid"
borderwidth="1"
bordercolor="Black" />
<items>
<asp:menuitem navigateurl="Home.aspx"
text="Non-Selectable"
tooltip="Non-Selectable"
Selectable="false">
<asp:menuitem navigateurl="Music.aspx"
text="Music"
tooltip="Music">
<asp:menuitem navigateurl="Classical.aspx"
text="Classical"
tooltip="Classical"/>
<asp:menuitem navigateurl="Rock.aspx"
text="Rock"
tooltip="Rock"/>
<asp:menuitem navigateurl="Jazz.aspx"
text="Jazz"
tooltip="Jazz"/>
</asp:menuitem>
<asp:menuitem navigateurl="Movies.aspx"
text="Disabled"
tooltip="Disabled"
Enabled="false">
<asp:menuitem navigateurl="Action.aspx"
text="Action"
tooltip="Action"/>
<asp:menuitem navigateurl="Drama.aspx"
text="Drama"
tooltip="Drama"/>
<asp:menuitem navigateurl="Musical.aspx"
text="Musical"
tooltip="Musical"/>
</asp:menuitem>
</asp:menuitem>
</items>
</asp:menu>
</form>
</body>
</html>
<%@ 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 Selectable and Enabled properties Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Menu Selectable and Enabled properties Example</h3>
Note that Home, set to Selectable=false, is unselectable, but still shows all child items.<br />
Movies, set to Enabled=false, is unselectable, is greyed out, and does not show child items. <br />
<asp:menu id="NavigationMenu"
staticdisplaylevels="1"
staticsubmenuindent="10"
orientation="Vertical"
target="_blank"
runat="server">
<dynamicmenustyle backcolor="LightSkyBlue"
forecolor="Black"
borderstyle="Solid"
borderwidth="1"
bordercolor="Black" />
<items>
<asp:menuitem navigateurl="Home.aspx"
text="Non-Selectable"
tooltip="Non-Selectable"
Selectable="false">
<asp:menuitem navigateurl="Music.aspx"
text="Music"
tooltip="Music">
<asp:menuitem navigateurl="Classical.aspx"
text="Classical"
tooltip="Classical"/>
<asp:menuitem navigateurl="Rock.aspx"
text="Rock"
tooltip="Rock"/>
<asp:menuitem navigateurl="Jazz.aspx"
text="Jazz"
tooltip="Jazz"/>
</asp:menuitem>
<asp:menuitem navigateurl="Movies.aspx"
text="Disabled"
tooltip="Disabled"
Enabled="false">
<asp:menuitem navigateurl="Action.aspx"
text="Action"
tooltip="Action"/>
<asp:menuitem navigateurl="Drama.aspx"
text="Drama"
tooltip="Drama"/>
<asp:menuitem navigateurl="Musical.aspx"
text="Musical"
tooltip="Musical"/>
</asp:menuitem>
</asp:menuitem>
</items>
</asp:menu>
</form>
</body>
</html>
When this property is set to false
on a menu item, no action occurs when the menu item is clicked (selected). The pop-out image indicating child menu items for the menu item, if one exists, is still shown and available.
If you do not want any child menu items to appear for a menu item, set the Enabled property to false
.
Selectable applies only to menu items that can be selected, in the sense that clicking a menu item posts back and sets that item in the selected state. Note that a menu item that cannot be selected is still formatted as a link. This is for accessibility reasons, so that the menu item can cause an action to occur. Also, a menu item, even if it cannot be selected, may have child menu items that can be selected or that need to be displayed.
If you want to prevent a user from clicking a menu item, do one of the following:
Do not set NavigateUrl and set Selectable to false
.
Set the menu item's Enabled property to false
.
Product | Versions |
---|---|
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in