articles

Home / DeveloperSection / Articles / Checkbox in ASP.Net

Checkbox in ASP.Net

Pushpendra Singh6112 13-Oct-2010

The Checkbox control is used to display a check box. The Checkbox Web server control gives us an option to select. A checkbox is clicked to select and clicked again to deselect option. When a checkbox is selected, a check (a tick mark) appears indicating a selection.

Checkbox in ASP.Net


The main event of the Checkbox is the Checked Changed event

Code:

<asp:Label ID="Label2" runat="server" Text="Which programming language you know"></asp:Label><br />
        <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" OnCheckedChanged="CheckBox1_CheckedChanged"
            Text="C#" />
        <br />
        <asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="True" OnCheckedChanged="CheckBox2_CheckedChanged"
            Text="Java" />
        <br />
        <asp:CheckBox ID="CheckBox3" runat="server" AutoPostBack="True" OnCheckedChanged="CheckBox3_CheckedChanged"
            Text="VB" />
 
When you check the checkbox then CheckedChanged event will fire if  AutoPostBack="True"
 
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox1.Checked)
Label1.Text = CheckBox1.Text;
}
 
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox2.Checked)
{
Label1.Text = CheckBox2.Text;
}
if (CheckBox2.Checked & CheckBox1.Checked)
{
Label1.Text = CheckBox1.Text + CheckBox2.Text;
}
      
}
 
protected void CheckBox3_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox3.Checked)
Label1.Text = CheckBox3.Text;
}

 

Checkbox in ASP.Net

When you check the checkbox then CheckedChanged event will fire and it will show the checked value in the Label.


Updated 07-Sep-2019

Leave Comment

Comments

Liked By