By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,354 Members | 1,042 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,354 IT Pros & Developers. It's quick & easy.

RequiredFieldValidator on RadioButtons?

P: n/a
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

Dec 14 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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/defaul...tvalidatordemo
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Chris Ashley" <ch***********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
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

Dec 14 '05 #2

P: n/a
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;
}

"Chris Ashley" <ch***********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
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

Dec 14 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.