asp.net.ph

Skip Navigation Links

Responding to User Selection in a CheckBox Control

Controls You Can Use on Web Forms   ASP.NET Standard Controls   CheckBox and CheckBoxList Controls


When the user selects a CheckBox control, the control raises an event that you can respond to.

NOTE: The CheckBoxList control raises events differently than individual CheckBox controls. For details, see Responding to Changes in a List Control.

You might not need to respond directly to the selection event of a CheckBox control at all. You respond to the event only if it’s important to know when the user has changed the check box selection.

If you are only interested in the state of the check box when selected, and not whether it has changed, you can simply test the check box after the form has been posted to the server by a control such as a Button control. For details about determining whether a CheckBox control is selected, see Getting and Setting a CheckBox Control Value Programmatically.

To respond to a selection in a CheckBox control

  1. Define a method to handle the control’s CheckedChanged event ( occurs when a user clicks on the control ). For example

void myCheckChangedHandler ( object src, EventArgs e ) {
   // ... do your thing here ...
}
  C# VB
  1. Assign the handler to the onCheckedChanged event attribute of the CheckBox.
<asp:CheckBox onCheckedChanged="myCheckChangedHandler" runat="server" />

By default, the CheckedChanged event does not immediately cause the Web Forms page to be posted to the server. Instead, the event is raised in server code the next time the form is posted, as when a Button Web server control is clicked. To have the CheckedChanged event cause an immediate posting, set the CheckBox control’s AutoPostBack property to true.

CheckBox3.aspx
Run Sample | View Source
See Also

Adding CheckBox Controls to a Web Forms Page   Getting and Setting a CheckBox Control Value Programmatically



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note