Validator doesn't work if autopostback=true

M

Mad Scientist Jr

I'm having this issue where textbox A on my form is recalculated every
time textbox B, C, or D is changed. To complicate this, if dropdown D
= 1, for example, A = B + C, if dropdown D = 2, A = C * D. To do this,
Textbox B, C and D have autopostback set to True and depending on the
value of dropdown D, the appropriate formula is used. I also have
range validators on B, C and D to make sure the values are doubles in
the accepted range.

The problem is, the 'on change' postback fires even if the validators
finds an error. The validators display the error(s) but then the
postback happens and the page is rendered without any error messages.

Is there some way to specify that if the validator finds an error for
the textbox, then the autopostback should not happen?

I would hate to have to code the calculation or the validation in
javascript.

thanks
 
C

Craig Deelsnyder

Mad said:
I'm having this issue where textbox A on my form is recalculated every
time textbox B, C, or D is changed. To complicate this, if dropdown D
= 1, for example, A = B + C, if dropdown D = 2, A = C * D. To do this,
Textbox B, C and D have autopostback set to True and depending on the
value of dropdown D, the appropriate formula is used. I also have
range validators on B, C and D to make sure the values are doubles in
the accepted range.

The problem is, the 'on change' postback fires even if the validators
finds an error. The validators display the error(s) but then the
postback happens and the page is rendered without any error messages.

Is there some way to specify that if the validator finds an error for
the textbox, then the autopostback should not happen?

I would hate to have to code the calculation or the validation in
javascript.

thanks

Wrap up your 'on change' code with

if (Page.IsValid)
{
//only run if the validators are not 'tripped'
}

should always do this on event handlers when validators are involved, so
you don't have to worry about this scenario.
 

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,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top