RequiredFieldValidator on RadioButtons?

  • Thread starter Thread starter Chris Ashley
  • Start date Start date
C

Chris Ashley

I have a couple of RadioButtons both with the same GroupName. Is there
any way I can use a RequiredFieldValidator to ensure that at least one
of the RadioButtons in the group is selected? Setting ControlToValidate
to the GroupName doesn't seem to work, and obviously setting it to the
ID of one of the individual RadioButtons won't work.. any ideas?

Thanks in advance,

Chris
 
Chris,

Instead of using two separate RadioButtons use the RadioButtonList control.
Then you can set the RequiredFieldValidator's ControlToValidate to the
RadioButtonList control and it will require a selection.

By the way, if you ever need a RequiredFieldValidator for a checkboxlist
I've created one that I give away for free (with source code). There is a
demo of it here:
http://www.aboutfortunate.com/default.aspx?page=checkboxlistvalidatordemo


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
Chris - Radio Buttons do not support the Required Field Validator. You can
either have a button selected by default or employ javascript. Here's a
simple example that forces a user to select either a Male or Female radio
button. There are plenty of variations of this on the Internet if you do a
little digging:

if ( ( document.myForm.gender[0].checked == false ) && (
document.myForm.gender[1].checked == false ) )
{
alert ( "Please select either Male or Female" );
valid = false;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top