WebControl.Enabled Property
Gets or sets a value indicating whether the Web server control is enabled.
[Visual Basic] Public Overridable Property Enabled As Boolean [C#] public virtual bool Enabled {get; set;} [C++] public: __property virtual bool get_Enabled(); public: __property virtual void set_Enabled(bool); [JScript] public function get Enabled() : Boolean; public function set Enabled(Boolean);
Property Value
true if control is enabled; otherwise, false. The default is true.
Remarks
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.
Note The ability to enable or disable functionality is always available. However, dimming and locking the control only works in 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.
Note Not all controls support this property. See the indivual controls for details.
Example
[Visual Basic, C#, JScript] The following example illustrates how to enable and disable a TextBox control, inherited from the WebControl base class, by setting its Enabled property programmatically.
[Visual Basic] <%@ Page Language="VB" AutoEventWireup="True" %> <html> <body> <h3>Enabled Property of a Web Control<br></h3> <script language="VB" runat="server"> Sub SubmitBtn1_Click(sender As Object, e As EventArgs) TextBox1.Enabled = Not(TextBox1.Enabled) End Sub </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> [C#] <%@ 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> [JScript] <%@ Page Language="JScript" AutoEventWireup="True" %> <html> <body> <h3>Enabled Property of a Web Control<br></h3> <script language="JSCRIPT" runat="server"> function SubmitBtn1_Click(sender : Object, e : EventArgs){ 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>
[C++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
See Also
WebControl Class | WebControl Members | System.Web.UI.WebControls Namespace