ASP.NET - how to stop server check without request

I used ValidatorEnable to disable RequiredFieldValidator in javascript. However, with postback, the validation verified by the validator is still verified ... although I disabled the validator on the client.

I understand why this happens, since I only turned off client verification ... however, is there a good way to determine that I turned off client verification and then turned off server verification during postback?

+2
source share
3 answers

Peanuts, I just ran into the same problem as you. On the client side, I have javascript that disables the necessary field validators depending on their choice in the user interface. However, server-side validation still worked.

At boot time, I added a method to disable my validators using the same rules as javascript. In my case, it depended on the user choosing the switch:

this.requiredValidator.Enabled = this.myRadioButton.Checked; 

This seems to work on a SECOND boot, but not in the first place. After debugging, I found that the wrong radio button is considered verified when this line is run. The view / publish state was not applied to the control at the moment when I checked it to disable my validator. The reason I posted this at boot time was to make sure I turned off the validator before it started.

So, it looks like the solution is similar to the line above AFTER ViewState, but before the checks.

Overloading the Validate () method, as suggested by palehorse, worked and allowed me to make sure that server-side validators were enabled / disabled based on the user's current choices.

0
source

You could turn off client validation (presumably using JavasScript?), As well as adjust the values โ€‹โ€‹in hidden input, which you could request in the page load method. This way you can check the value of the hidden input (via the Request.Form {] array) to disable the server-side validators before triggering the validation event.

Another option is to override the Validate () method to disable validators based on the same rules that hid them on the client side.

+3
source

From your question it is not clear what you turn off. RequiredFieldValidator has the Enabled property and EnableClientScript.

If you want to disable verification on both the client and the server, you must set Enabled to false.

To disable only the client side, set EnableClientScript to false.

+2
source

All Articles