|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
How to: Respond to User Selection in a CheckBox Web Server Control
When the user selects acontrol, the control raises an event that you can respond to.
Thecontrol raises events differently than individual CheckBox controls do. For details, see .
You might not need to respond directly to the check event of a CheckBox control at all. You respond to the event only if it is important to know when the user has changed the check box selection. If you are interested only 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. For details, see.
To respond to a selection in a CheckBox control
Create an event handler for the control'sevent.
By default, the CheckedChanged event does not immediately cause the page to be posted to the server. Instead, the event is raised in server code the next time the form is posted. To have the CheckedChanged event cause an immediate posting, set the CheckBox control'sproperty to true.
The following example displays "True" or "False" in a Label Web server control to reflect the latest change in a CheckBox control.
Protected Sub CheckBox1_CheckedChanged(ByVal sender As _ System.Object, ByVal e As System.EventArgs) Handles _ CheckBox1.CheckedChanged Label1.Text = "CheckBox1 selection is: " & _ CheckBox1.Checked.ToString() End Sub