Required Validation on Radio Button Group

  • Thread starter Thread starter ryanmhuc
  • Start date Start date
R

ryanmhuc

How would you do a required validation on a radio button group? I do
not want to use a RadioButtonList control and the CustomValidator
control only fires if their is a value in the ControlToValidator
control.
 
Because RadioButtons are in groups and there is always one selected (unless
there is not a default selected one when the page loads), most people do not
normally do validation on RadioButtons. If your situation is that you want
to make sure the user selects a RadioButton when none are selected by
default, you have several options:

1. Use the CustomValidator. Place the ID of any one of the RadioButtons in
the ControlToValidate property, you are still allowed to look at the other
RadioButtons when implementing the EvaluateIsValid method.

2. Write a custom control by inheriting from the BaseValidator class (this
is not hard to do)

3. Set the Checked property of any one of the RadioButtons to true so that
you do not need to worry about the validation

Hopefully this helps!
 
Back
Top