How to know Check Status of CheckBox programmatically

Hi, Here in this ASP.Net tutorials  are to lean how to check the check status of Checkbox on Button Click Event programmatically.

Means, on button click event check the checkbox is checked or not.

STEP 1 – Design the asp.net web page :

 <table border=”1″ bordercolor=”#000000″ style=”z-index: 100; left: 272px; position: absolute;
top: 72px”>
<tr>
<td colspan=”3″ style=”width: 582px”>
<asp:Image ID=”Image1″ runat=”server” ImageUrl=”~/img/newimg.png” /></td>
</tr>
<tr>
<td colspan=”3″ rowspan=”2″ style=”width: 582px; height: 21px; text-align: center”>
<table>
<tr>
<td style=”width: 181px; height: 24px; text-align: right;”>
Check/Uncheck Checkbox</td>
<td style=”width: 255px; height: 24px;”>
&nbsp;<asp:CheckBox ID=”CheckBox1″ runat=”server” Text=”CheckBox” /></td>
</tr>
<tr>
<td style=”width: 181px”>
</td>
<td style=”width: 255px”>
<asp:Button ID=”btnchecked” runat=”server” OnClick=”btnchecked_Click” Text=”Checked” />&nbsp;</td>
</tr>
<tr>
<td style=”width: 181px”>
</td>
<td style=”width: 255px”>
<asp:Label ID=”lblanswer” runat=”server”></asp:Label></td>
</tr>
</table>
</td>
</tr>
<tr>
</tr>
</table>

– The ASP.Net Example output is like :

CheckBox control in ASP.Net with C#
CheckBox control in ASP.Net with C#

STEP 2 – Write below code on Button Click Event on .aspx.cs page.

protected void btnchecked_Click(object sender, EventArgs e)
{
if (CheckBox1.Checked == true)
{
lblanswer.Text = “Checkbox is Checked”;
}
else
{
lblanswer.Text = “Checkbox is Un-Checked”;
}
}

The ASP.Net Checkbox Example output is :

CheckBox control in ASP.Net with C#
CheckBox control in ASP.Net with C#

The ASP.Net Checkbox Example output is :

CheckBox control in ASP.Net with C#
CheckBox control in ASP.Net with C#

– I hope this ASP.Net Example will help you……..

Leave a Reply

Your email address will not be published. Required fields are marked *