Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validators: Do they Stay disabled on postback when disabled ClientSide?

I have been learning alot about the standard asp.net Validators, and my latest discovery was about how to disable a validator client side, which was pretty cool.

now, if my initial post has the validator enabled, but client side, i disable it, does the server side recognize the client side change, and keep it, or does it get re-enabled the the page is sent back to the user?

Thanks!

Nate

like image 359
Nathan Tregillus Avatar asked Oct 18 '25 04:10

Nathan Tregillus


1 Answers

.NET Server side validator controls will be reset to whatever they have been set to last in the server side code during a postback.

So for example if you have set a required field validator to rqvControl.enabled = true in its .aspx tag, then after a postback it will be enabled no matter what its state was client side.

If you are setting the state of a validator on the client side, and you want to persist it, then you will need to set a value that you can read in your server code during a postback. This can be as simple as setting a hidden field value from your javascript that is doing the enable/disable operation. In your codebehind just handle the enabled state of your validator based off the value in your hidden field.

like image 105
Tj Kellie Avatar answered Oct 20 '25 23:10

Tj Kellie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!