ASP.NET - 如何阻止不需要的服务器验证 [英] ASP.NET - how to stop unrequired server validation

查看:99
本文介绍了ASP.NET - 如何阻止不需要的服务器验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用ValidatorEnable禁用javascript中一个RequiredFieldValidator。但是在回发被验证器验证的控制仍然是有效的......即使我禁用了客户端上的验证。

I have used ValidatorEnable to disable a RequiredFieldValidator in javascript. However on postback the control being validated by the validator is still validated ... even though I disabled the validator on the client.

我明白为什么,因为我只禁用客户端验证这种情况发生......但有一个很好的方法来确定我已经禁用了客户端验证,并然后禁用发的服务器验证?

I understand why this is happening since I've only disabled the client validation ... however is there a nice way to determine that I've disabled the client validation and to then disable the server validation on postback?

推荐答案

花生,我刚中遇到你同样的问题。在客户端我的javascript禁用必填字段校验取决于它们在UI的选择。但是,服务器端验证仍然射击。

Peanut, I just encounted the same issue you are. On the client-side I have javascript that disables required field validators depending on their selections in the UI. However, the server side validation was still firing.

在负荷,我说我用对的JavaScript相同的规则来禁用我的验证的方法。就我而言,它取决于用户的选择单选按钮:

During load, I added a method to disable my validators using the same rules I have on the javascript. In my case, it depended on the user's selection of a radio button:

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

这似乎在第二页负荷工作,但不是第一个。经过调试,我发现错了单选按钮被认为是在这条线被烧成进行检查。视图状态/后的数据没有被应用到时我检查以禁用我的验证点控制。我在负载放置在此的原因是为了确保我禁用了验证它发射了。

This seems to work on the SECOND page load, but not the first. After debugging, I discovered that the wrong radio button is considered to be checked when this line was firing. The View State/Post Data wasn't applied to the control at the point when I was checking it to disable my validator. The reason I placed this during load was to make sure I disabled the validator before it fired.

所以,解决的办法似乎是有一些像上面的ViewState后线,但在此之前的验证。

So, the solution seems to be to have something like the line above AFTER ViewState, but BEFORE validators.

重载的validate()方法,如palehorse建议,工作,让我确保根据用户的当前选择的服务器端验证被启用/禁用。

Overloading the Validate() method, as palehorse suggested, worked and allowed me to ensure the server side validators were enabled/disabled based on the current selections of the user.

这篇关于ASP.NET - 如何阻止不需要的服务器验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆