How to use CheckBox control in c#

CheckBox Server Control
CheckBox is an web server control. CheckBox allow web site visitor to select (checked) a true or false condition. So the CheckBox control create a CheckBox on web forms page which allow user to switch between a true or false state. CheckBox Text property create a caption for it. we can left or right align caption by using CheckBox TextAlign property.

The CheckBox control has many properties that help us to change looks and style such as ForeColor, BorderColor, BackColor, BorderStyle, BorderWidth, CssClass, EnableTheming, Font, Height, SkinID, ToolTip, Width etc.

If we want to determine whether CheckBox is checked (selected) then we need to test the CheckBox Checked property. CheckBox AutoPostBack property value true enable automatic posting to server. CheckBox CheckedChanged event raised when someone change the CheckBox true or false state. .NET developers can write an event handler for CheckedChanged event. Using CheckedChanged event we can know the CheckBox current state and can perform any task when page post to server.

The following example demonstrate us how to use CheckBox control in Here we create a web form with a Label and two CheckBox control. When someone check the first CheckBox then the label show a message that he checked first CheckBox. The second CheckBox programmatically checked when user checked the first CheckBox.

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

<!DOCTYPE html>

<script runat="server">
    protected void CheckBox1_CheckChanged(object sender, System.EventArgs e) {

        if (CheckBox1.Checked == true) {
            Label1.Text = "WOW! You are a member of an user group.";
            Label1.ForeColor = System.Drawing.Color.Green;
            Label1.Text = "You are not a member of any user group.";
            Label1.ForeColor = System.Drawing.Color.Crimson;

<html xmlns="">
    <head runat="server">
        <title>How to use CheckBox control in</title>
<body style="padding:25px">
    <form id="form1" runat="server">
        <h2 style="color:MidnightBlue; font-style:italic;">      
            How to use CheckBox control
        <hr width="450" align="left" color="Gainsboro" />
            Font-Names="Comic Sans MS"
        <br /><br />
            Text="Are you an user group member?" 
More examples