CheckBox Control in ASP.Net

In previous server control post we had discussed about MultiView Control and ListBox Control and FileUpload Control and Adrotator Control and RadioButton Control and DropDownList Control and TextBox Control.

ASP.Net CheckBox Control

CheckBox control is an web server control. CheckBox control visually as square on web forms. The Checkbox control allow user to check square or uncheck square.

In CheckBox control check and uncheck checkbox specify by the checked property of check box true or false.

If checkbox control square ticked then checked = true and unchecked then checked=false.

We can drag the checkbox control from toolbox and drop it to on web forms shows like below. Checkbox control allow user to do either checked(tick) or unchecked (untick) the checkbox control in

CheckBox Control ASP.Net C# Example

let’s take a simple checkbox exmaple to understand checkbox checked or unchecked.

ASP.Net CheckBox Control

ASP.Net CheckBox Control


Here is the html design source code of web page.

After design web page with a checkbox, a button and a label control shows like below screen.

In below figure we have not checked the checkbox and click on select button then we get answer in label control like Checkbox is unchecked.

ASP.Net CheckBox Control

ASP.Net CheckBox Control

Now, check the checkbox control and then click button to display message in label like CheckBox is Checked.

Here is the c# code behind code for button click event for check whether checkbox is checked or unchecked.

ASP.Net CheckBox Control

ASP.Net CheckBox Control

There is other important property of checkbox is Autopostback.

Autopostback means when we receive request from user and go to server with request and proceed the request on server and get back to user with response as a result, the all round trip known as postback.

If we set Autopostback = true on checkbox then the checkbox control CheckedChanged event enable for user, means we go to the code behind while check or uncheck checkbox control.

below example shows how autopostback will work in checkbox control.

Design web page with two checkbox control along with a label control.

Set both checkbox contorl AutoPostBack = true.

CheckBox Control AutoPostBack ASP.Net Example

The html design source code is:

Here, we can check only one checkbox at a time, if we check one checkbox and try to check other checkbox the first checkbox control automatically unchecked by using the checkbox_CheckedChanged events.

below screen shows the design out put of checkbox autopostback example.

AutoPostBack in checkbox control in c#

AutoPostBack in checkbox control in c#

write below code on code behind page for both checkbox CheckedChanged events.

In below example when we  check the Red checkbox control then RED CheckBox is checked message display on label control. If we check green checkbox control then the Red checkbox control automatically unchecked and the label control display with Green CheckBox is checked message.

AutoPostBack in checkbox control in c#

AutoPostBack in checkbox control in c#

In below screen shows the Green checkbox control is checked, the label display message as Green CheckBox is checked.

AutoPostBack in checkbox control in c#

AutoPostBack in checkbox control in c#

I hope you like this checkbox control post.

Leave a Reply

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

5 + 8 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">