RequiredFieldValidator on RadioButtons?

Discussion in 'ASP .Net' started by Chris Ashley, Dec 14, 2005.

  1. Chris  Ashley

    Chris Ashley Guest

    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 Ashley, Dec 14, 2005
    #1
    1. Advertising

  2. 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 Ashley" <> wrote in message
    news:...
    >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. Justin Gengo, Dec 14, 2005
    #2
    1. Advertising

  3. Chris  Ashley

    Chris Huddle Guest

    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" <> wrote in message
    news:...
    >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 Huddle, Dec 14, 2005
    #3
  4. Chris  Ashley

    adharbert

    Joined:
    Aug 7, 2006
    Messages:
    1
    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.
     
    adharbert, Aug 7, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sean
    Replies:
    1
    Views:
    390
    Ken Cox [Microsoft MVP]
    Aug 6, 2003
  2. RB

    RadioButtons & DataGrid

    RB, Aug 11, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    426
  3. Robert H
    Replies:
    0
    Views:
    457
    Robert H
    Dec 4, 2003
  4. Carlos
    Replies:
    0
    Views:
    288
    Carlos
    Feb 18, 2005
  5. =?Utf-8?B?Q2hyaXN0aWFhbiBOaWV1d2xhYXQ=?=

    Dynamically add RadioButtons in Repeater

    =?Utf-8?B?Q2hyaXN0aWFhbiBOaWV1d2xhYXQ=?=, May 26, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    983
    =?Utf-8?B?Q2hyaXN0aWFhbiBOaWV1d2xhYXQ=?=
    May 26, 2005
Loading...

Share This Page