RequiredFieldValidator on RadioButtons?

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
 
S

S. Justin Gengo

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
 
C

Chris Huddle

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;
}
 
Joined
Aug 7, 2006
Messages
1
Reaction score
0
RadioButton Validator

You can't use a required field, but you should be able to build this by using the CustomValidator. I've used that with checkboxes and I know those two operate the same way. You basically have to build a javascript function and reference it in the control. A little screwy, but it works.
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top