Validation of RadioButtonList

C

cpnet

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.
 
C

cpnet

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.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top