5.3. Collecting RadioButtonList Controls

The ASP.NET RadioButtonList control allows you to create many radio buttons with one control. In this section, you build a survey form, work with the Collection editor, and hook up an event handler.

5.3.1. Creating the basic page interface

The survey interface consists of a prompt, a set of radio buttons as choices, a button, and an area for a response. Follow these steps to create the basic interface.

  1. In the ASP.NET page Design view, add a Label control with the ID lblPrompt and set the Text value to Rate Your Fear of the Borg.

  2. From the Toolbox, drop a RadioButtonList control on the design surface and set its ID to rblBorg.

  3. Add another Label with the ID lblResponse and a Button control.

Bingo! And events

Think of a game of Bingo where players are filling their cards with markers. Suddenly, a hand shoots into the air and a player shouts, "Bingo!" That's an event.

Consider the player with the filled card as an ASP.NET control that raises an event called Bingo. The game's assistants are event handlers who intervene when someone claims to have a full card. The following pseudo-code (unusable code that represents a programming idea) shows how you might handle a Bingo event.

Protected Sub
   BingoPlayer1_Bingo _
    (ByVal player As Object, _
    ByVal e As _
   System.BingoEventArgs)
    Dim blnIsValidBingo as _
  boolean
    Dim walker as New _
  Assistant()
    blnIsValidBingo = _
  walker.Verify(e.Card)
End Sub

In ASP.NET, when someone clicks a button, the button doesn't ...

Get ASP.NET 3.5 For Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.