asp.net - Change CheckBox checked status by another CheckBox

Change CheckBox checked status by another CheckBox programmatically
CheckBox is an asp.net web server control which allow users to select a true or false condition. so checkbox have two possible status checked (selected) and unchecked. we can checked a checkbox programmatically by depending on another checkbox checked status.

checkbox Checked property get or set a value indicating whether checkbox control is checked. so we can get the checked status of a checkbox control by its 'Checked' property. in this example we checked a checkbox programmatically by depending on another checkbox checked status. when someone checked the first checkbox then we programmatically checked the second checkbox and if someone unchecked the first checkbox then we also unchecked the second checkbox. to do it, we uses the checkbox CheckedChanged event.

the following asp.net c# example code demonstrate us how can we checked or unchecked a checkbox control depending on another checkbox checked status.
RelatedCheckBox.aspx
<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected void CheckBox1_CheckedChanged(object sender, System.EventArgs e)
    {
        if (CheckBox1.Checked == true)
        {
            CheckBox2.Checked = true;
        }
        else
        {
            CheckBox2.Checked = false;
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to change CheckBox checked status by another CheckBox programmatically</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Red">CheckBox Changed By Another CheckBox</h2>
        <asp:CheckBox
             ID="CheckBox1" 
             runat="server"
             Text="Check The CheckBox and Change Another CheckBox."
             AutoPostBack="true"
             ForeColor="SeaGreen"
             OnCheckedChanged="CheckBox1_CheckedChanged"
             Font-Bold="true"
             />
        <br /><br />
        <asp:CheckBox
             ID="CheckBox2" 
             runat="server"
             Text="Dependable CheckBox."
             AutoPostBack="false"
             ForeColor="SeaGreen"
             Font-Bold="true"
             />
    </div>
    </form>
</body>
</html>








Related asp.net examples