I have 20 RadioButtonList
s on a page.
I need to create a validation method to ensure that at least one of these RadioButtonList
s has an item selected.
What kind of validation would I need to use for this?
I have 20 RadioButtonList
s on a page.
I need to create a validation method to ensure that at least one of these RadioButtonList
s has an item selected.
What kind of validation would I need to use for this?
I use an extension method that works for ListControls
You could set a default for your RadioButtonList which would mean a user could never not select an option and you would not need all the validation code
EDIT As pointed out in a comment below this would not be sufficient by itself as a means of validation. It is good practice to validate all user input on the server-side also.
EDIT: Updated question based on comments and clarification.
If you are validating against multiple
RadioButtonList
s then you need to use aCustomValidator
and implement the server side check.Here is some test markup:
Use the following extension method to find all the
RadioButtonList
controls (Source):Then implement the server side
CustomValidator
check:I have tested the above example and it seems to do exactly what you need. You should be able to switch it to VB pretty easily. Hope this solves your problem.