WebControl.Enabled Property

Gets or sets a value indicating whether the Web server control is enabled.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

[BindableAttribute(true)] 
[ThemeableAttribute(false)] 
public virtual bool Enabled { get; set; }
/** @property */
public boolean get_Enabled ()

/** @property */
public void set_Enabled (boolean value)

public function get Enabled () : boolean

public function set Enabled (value : boolean)

Property Value

true if control is enabled; otherwise, false. The default is true.

Use the Enabled property to specify or determine whether a control is functional. When set to false, the control appears dimmed, preventing any input from being entered in the control.

NoteNote

Not all browsers support this property. Dimming and locking the control only works in browsers that are compatible with Microsoft Internet Explorer version 4 and later.

This property propagates down the control hierarchy. Therefore, disabling a container control will disable all child controls within that container.

NoteNote

When creating a custom composite control, this behavior does not apply to controls that have not yet created their child controls. You must either set the enabled state of the child controls when they are created, or override the Enabled property to call the EnsureChildControls method.

Not all controls support this property. See the individual controls for details.

This property cannot be set by themes or style sheet themes. For more information, see ThemeableAttribute and ASP.NET Themes and Skins Overview.

TopicLocation
Walkthrough: Validating User Input in a Web Forms PageBuilding ASP .NET Web Applications in Visual Studio

The following example illustrates how to enable and disable a TextBox control, inherited from the WebControl base class, by setting its Enabled property programmatically.

NoteNote

The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information on the Web Forms code model, see ASP.NET Web Page Code Model.

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

<html>
 <body>
 
     <h3>Enabled Property of a Web Control<br></h3>
 
 <script language="C#" runat="server">
 
     void SubmitBtn1_Click(Object sender, EventArgs e) {
        TextBox1.Enabled = !(TextBox1.Enabled);
     }
 
 </script>
 
 <form runat=server>
 
     <asp:TextBox id="TextBox1" BackColor="LightBlue" runat="server"/>
     <p>
 
     <asp:TextBox id="TextBox2" BackColor="LightGreen" runat="server"/>
     <p>
 
     <asp:Button id="SubmitBtn1" OnClick="SubmitBtn1_Click" 
     Text="Click to disable/enable the light blue text box" 
     runat="server"/>
     <p>
     
 </form>
 
 </body>
 </html>
 

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show: