Validator doesn't work if autopostback=true

  • Thread starter Thread starter Mad Scientist Jr
  • Start date Start date
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
 
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.
 
Back
Top