Skip to Content
ASP.NET 3.5 For Dummies®
book

ASP.NET 3.5 For Dummies®

by Ken Cox
February 2008
Intermediate to advanced
428 pages
8h 52m
English
For Dummies
Content preview from ASP.NET 3.5 For Dummies®

5.2. Pushing for Choices with the RadioButton Control

ASP.NET RadioButton controls work as a team; however, only one player can be "on" at a time. Figure 5-2 shows three RadioButton controls acting as a group. All three share the same GroupName value. When a user clicks the Submit button, an event handler subroutine (refer to the "Bingo! And events" sidebar) executes and reports which radio button is checked.

Figure 5-2. You can select only one radio button in a group at a time.

Follow these steps to create a group of RadioButton controls and display which one a user has pushed:

  1. From the Toolbox, add to the ASP.NET page three RadioButton controls, a Button control (Button1) and a Label control (lblText).

  2. Set the RadioButton control's ID values to radTo, radMtl, and radVcr; the Text properties to Toronto, Montreal, and Vancouver; and the GroupName properties to cities.

  3. Double-click the button to create a handler for the Button control's Click event and use the following code inside the Click event handler subroutine:

    If radTo.Checked Then
        lblText.Text = "Choice: " & radTo.Text
    ElseIf radMtl.Checked Then
        lblText.Text = "Choice: " & radMtl.Text
    ElseIf radVcr.Checked Then
        lblText.Text = "Choice: " & radVcr.Text
    Else
        lblText.Text = "No choice made."
    End If

The code tests whether the Toronto radio button's Checked property is True (that is, whether the button is pushed). If so, it assigns ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

ASP.NET 3.5 Unleashed

ASP.NET 3.5 Unleashed

Stephen Walther
ASP.NET 4 Unleashed

ASP.NET 4 Unleashed

Stephen Walther, Kevin Hoffman, Nate Dudek

Publisher Resources

ISBN: 9780470195925Purchase book