CheckBox Control Check/Uncheck on Button Click Event in .Net

– Here we are going to learn, Checkbox control is Checked / Unchecked  on Button Click Event.

STEP 1 – Design the asp.net web page like :

<body>
<form id=”form1″ runat=”server”>
<div>
<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=”https://meeraacademy.com/wp-content/themes/elemin/uploads/logo/meeralogo.gif” /></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;”>
<asp:Button ID=”btnchecked” runat=”server” OnClick=”btnchecked_Click” Text=”Checked” />&nbsp;
<asp:Button ID=”btnUnchecked” runat=”server” OnClick=”btnUnchecked_Click” Text=”Unchecked” /></td>
</tr>
<tr>
<td style=”width: 181px”>
</td>
<td style=”width: 255px”>
&nbsp;<asp:CheckBox ID=”CheckBox1″ runat=”server” Text=”CheckBox” /></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>

</div>
</form>
</body>

– The Out Put is :

CheckBox Control Example in ASP.Net with C#
CheckBox Control Example in ASP.Net with C#

STEP 2 – Now, write Below code at Checked Button Click Event:

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

– The Out Put of ASP.Net Example is:

CheckBox Control Example in ASP.Net with C#
CheckBox Control Example in ASP.Net with C#

STEP 3 – Write below code at Unchecked Button Click Event in ASP.Net

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

-The Out Put of CheckBox Control Example is:

CheckBox Control Example in ASP.Net with C#
CheckBox Control Example in ASP.Net with C#

Leave a Reply

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