views:

528

answers:

2

Hello!

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

A: 

How do you disable them on the client side? I would imagine that unless the act of disabling them on the client does a postback that the viewstate will remain unchanged and hence they will be reenabled on the next page refresh (just theorizing here).

Try it yourself and if it doesn't work, you could perhaps add a hidden field which you also set on the client when you disable the validator and then check that field on the server side during a postback to know whether to enable/disable them there.

Ben Daniel
I am using the method included in the WebUIValidation.js scriptValidatorEnableI'll probably get around to it, but i thought it would be a good place to enter this know information.
N8
+5  A: 

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

Tj Kellie
wonderful. thanks for the answer!
N8