Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > RequiredFieldValidator on RadioButtons?

Reply
Thread Tools

RequiredFieldValidator on RadioButtons?

 
 
Chris Ashley
Guest
Posts: n/a
 
      12-14-2005
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

 
Reply With Quote
 
 
 
 
S. Justin Gengo
Guest
Posts: n/a
 
      12-14-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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
>



 
Reply With Quote
 
 
 
 
Chris Huddle
Guest
Posts: n/a
 
      12-14-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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
>



 
Reply With Quote
 
adharbert adharbert is offline
Junior Member
Join Date: Aug 2006
Posts: 1
 
      08-07-2006
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RequiredFieldValidator control giving problems. Please help. Gaurav ASP .Net 1 08-20-2003 02:26 PM
Setting Focus on field when RequiredFieldValidator fails - This Works! Steve Yerkes ASP .Net 3 08-01-2003 08:38 AM
Going crazy with requiredfieldvalidator controls . Kindly help me Navin ASP .Net 3 07-28-2003 06:50 PM
Question about RequiredFieldValidator pc ASP .Net 2 07-28-2003 03:30 AM
ASP:RequiredFieldValidator control is not working on Netscape 7. Rob ASP .Net 4 07-18-2003 05:34 PM



Advertisments