Grouping Radio Buttons in ASP .NET MVC 2

Here's a simple issue I ran into today when dealing with radio buttons in an ASP .NET MVC 2 application.

Radio buttons should only allow the user to select a single option out of multiple choices. This should be enforced by only allowing one radio button to be selected for each option set. But, what if your application has multiple options that all need radio buttons? How do you distinguish the radio buttons from one option from the other.

This is where groups comes in. By setting the GroupName property for each of your radio buttons, you can specify which buttons to associate to an option.

  <asp:RadioButton ID="ActionMatch" GroupName="RegexActions" Checked="true" Text="Match" runat="server" />
  <asp:RadioButton ID="ActionReplace" GroupName="RegexActions" Text="Replace" runat="server" />

Also, note that in ASP .NET MVC 2 there is no default group, so you must define a GroupName in order for the radio buttons to work properly.

Creative Commons License

What do you think?