How can I validate that at least 1 radio button is selected?
+5
A:
If all the radio buttons are part of the same RadioButtonList, you can use a simple RequiredFieldValidator. Here's an example of that:
<asp:RadioButtonList
ID="RadioButtonList1"
runat="server"
RepeatColumns="3">
<asp:ListItem>Red</asp:ListItem>
<asp:ListItem>Yellow</asp:ListItem>
<asp:ListItem>Blue</asp:ListItem>
<asp:ListItem>Green</asp:ListItem>
</asp:RadioButtonList>
<asp:RequiredFieldValidator
ID="ReqiredFieldValidator1"
runat="server"
ControlToValidate="RadioButtonList1"
ErrorMessage="You must Select your favorite color!">*
</asp:RequiredFieldValidator>
If you have RadioButtons in different RadioButtonLists and you want to validate that at least one is selected across multiple lists, then you would need a CustomValidator.
Jose Basilio
2009-05-02 15:33:52
@Blankman - Did this answer help you? If so, please accept it.
Jose Basilio
2009-05-27 21:26:19
+2
A:
Another way might be if you checked one of them by default, during pageload (maybe the one you think most users will select) then the user will be "forced" to change the selection or continue with the default option, in this way you make sure there is always an option selected.
Izabela
2009-05-02 15:42:57
in same cases, you want force the user to make a choice. creating a default choice is not the same thing.
Homer
2010-07-21 16:02:52