Some sample radio button form elements:

Default No-Frills HTML Radio Button:
HTML Radio Button With An Associated Value:
Multiple HTML Radio Buttons With the Same Name:

ASP.NET RadioButton Control:
ASP.NET RadioButtonList Control:




Let's check out our values just submitted:

FYI: Note that the above form submits back to this same page. If you haven't yet submit the form then there won't be any values in the text below since they are retrieved from the form. In this case, the values reflected are simply the defaults and are the same results you would get if you submitted the form without selecting anything.

Just because we're using ASP.NET doesn't mean we have to use ASP.NET server controls. The first couple samples use plain old HTML and work just fine. In fact, unless you need the functionality offered by the RadioButton or RadioButtonList controls using plain old HTML actually uses fewer server resources!

Default No-Frills HTML Radio Button

By default, an HTML radio button element returns nothing if it wasn't enabled and a value of "on" if it was. So by checking it's value we can determine if it was enabled or not when the form was submitted. The Default No-Frills HTML Radio Button was: Disabled.

HTML Radio Button With An Associated Value

If you don't like the fact that the radio button returns the value of "on" it's really easy to change. Simply add a value parameter and assign to it what you'd like the value returned by the radio button to be. The HTML Radio Button With An Associated Value returned: .

Multiple HTML Radio Buttons With The Same Name

Similarly to the checkbox, the scenario where you have a set of radio buttons all with the same name is probably one of the most useful ways to use this type of input tag. The main difference is that instead of allowing a user to specify multiple answers to one question, the radio button element ensures that one and only one selection is choosen from among the group of buttons that share a common name.

The Multiple Radio Buttons With The Same Name (which ensures that only one choice is selected) returned: .

ASP.NET RadioButton Control

This is just a plain old ASP.NET RadioButton control, but just by it being an ASP.NET control we get all the associated benefits. For example, we can programmatically manipulate it (like I do by adding the label to it) and it keeps its state across page reloads.

ASP.NET RadioButton Control was: Disabled.

ASP.NET RadioButtonList Control

This is the ASP.NET control for dealing with a group of radio buttons. You can do all sorts of cool stuff with it. I'm going to keep things pretty simple, but I do play with the RepeatLayout and RepeatDirection and use databinding to fill the list with the individual radio buttons.

ASP.NET RadioButtonList Control contained the following selected items: .


Click here to read about and download the source code.