asp.net - How to enable and disable a CheckBox programmatically

Enable and disable CheckBox programmatically
CheckBox is an asp.net web server control. this server control display a check box on web browser that allows the user to select a true or false condition. CheckBox control has a built in property to enable or disable it programmatically at run time.

CheckBox Enabled property get or set a value that indicate whether the CheckBox control is enabled. This property value type is System.Boolean. So we can only assign true or false for this property value. If we set the CheckBox Enabled property value to 'true' then it will enabled the CheckBox on web page. And if we set the Enabled property value to 'false' then the CheckBox will be disable in web browser. Normally a disable control appear as dimmed in web browser.

The following asp.net c# example code demonstrate us how can we enable or disable a CheckBox control dynamically at run time in an asp.net application.
CheckBoxDisable.aspx

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

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        CheckBox1.Enabled = false;
        Label1.Text = "CheckBox Disable.";
    }
    protected void Button2_Click(object sender, System.EventArgs e)
    {
        CheckBox1.Enabled = true;
        Label1.Text = "CheckBox Enable.";
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to enable disable CheckBox programmatically</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Green">asp.net CheckBox example: Enable Disable</h2>
        <asp:Label 
             ID="Label1"
             runat="server"
             Font-Size="Large"
             ForeColor="Crimson"
             >
        </asp:Label>
        <br /><br />
        <asp:CheckBox
             ID="CheckBox1" 
             runat="server"
             Text="Check The CheckBox."
             AutoPostBack="false"
             ForeColor="DodgerBlue"
             />
        <br /><br />
        <asp:Button 
             ID="Button1" 
             runat="server" 
             ForeColor="BlueViolet"
             Text="Disable CheckBox"
             OnClick="Button1_Click"
             Font-Bold="true"
             />
        <asp:Button 
             ID="Button2" 
             runat="server" 
             Font-Bold="true"
             ForeColor="BlueViolet"
             Text="Enable CheckBox"
             OnClick="Button2_Click"
             />
    </div>
    </form>
</body>
</html>
More asp.net examples