asp.net.ph

Skip Navigation Links

Responding to a User Selection in a RadioButton Group

Controls You Can Use on Web Forms   ASP.NET Standard Controls   RadioButton and RadioButtonList Controls


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

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

You might not need to respond directly to the selection event of a RadioButton control at all. You respond to the event only if it’s important to know when the user has made a change to the selection in a radio button group.

If you are only interested in knowing which radio button is selected, and not whether selection has changed, you can simply test radio button selection after the form has been posted to the server by a control such as a Button control. For details about determining which RadioButton control is selected, see Setting and Getting the Selection in a RadioButton Control.

Because each RadioButton Web server control is a separate control, each can raise an event individually; the radio button group does not raise an event as a whole.

To respond to a selection in a RadioButton 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 RadioButton.
<asp:RadioButton 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 RadioButton control’s AutoPostBack property to true.

RadioButton2.aspx
Run Sample | View Source
See Also

Adding Individual RadioButton Controls to a Web Forms Page   Setting and Getting the Selection in a RadioButton Control



© 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