all groups > asp.net webcontrols > december 2006 >
You're in the

asp.net webcontrols

group:

Validation of RadioButtonList


Validation of RadioButtonList cpnet
12/22/2006 8:55:04 PM
asp.net webcontrols:
I've added a RadioButtonList (with 2 choices, neither selected by default),
and a RequiredFieldValidator to a WebForm. Basically, I want a red asterisk
to appear beside the RadioButtonList until the user selects on of the
choices. I'd like this validation to fire on the client side. I've set
RequiredFieldValidator.ControlToValidate to my RadioButtonList. I've set
RadioButtonList.CausesValidation to "true" on the RadioButtonList. Still,
when the page is first rendered, I don't see the validation control display
my red asterisk. I added a button that does nothing but cause the form to
postback. Causing a postback with this button still doesn't make the
RequiredFieldValidator.Text show up. I must be doing something wrong, but I
can't figure out what.

Re: Validation of RadioButtonList cpnet
12/24/2006 6:21:58 PM
I was doing 2 things wrong:

1) I was setting the RequiredFieldValidator.InitialValue property (not
knowing what it does). I shouldn't have been setting this.
2) On Page_Load I should have been calling Page.Validate() if I wasn't
doing a post back, to force validation the first time the page is rendered.
I wasn't doing this.

Once I fixed these 2 things, it worked fine.

AddThis Social Bookmark Button