asp.net 使用 Javascript 禁用/启用验证器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10257260/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 00:30:57  来源:igfitidea点击:

asp.net disable/enable validator using Javascript

javascriptasp.netvalidation

提问by Jacques

I have a complex form requiring me to switch specific validators on or off depending on selections made by the user.

我有一个复杂的表单,需要我根据用户所做的选择打开或关闭特定的验证器。

ValidatorEnable seems to do the job, but it seems that when I call this method it actually fires the validation process as well, without the user actually hitting the submit button.

ValidatorEnable 似乎完成了这项工作,但似乎当我调用此方法时,它实际上也触发了验证过程,而用户实际上没有点击提交按钮。

Is that how it works?

它是这样工作的吗?

回答by Jacques

I eventually found the best way to do this was to use the following code:

我最终发现最好的方法是使用以下代码:

var validatorObject = document.getElementById('<%=ValidHasShippingLocationZip.ClientID%>');
validatorObject.enabled = false;
validatorObject.isvalid = true;
ValidatorUpdateDisplay(validatorObject);

回答by ValidfroM

I wrote some code seems can meet your requests. Iterate validators and enable these you needs.

我写了一些代码似乎可以满足您的要求。迭代验证器并启用这些你需要的。

   ValidatorEnable(validatorObj, true);

then clear the screen,erase the error info.

然后清屏,清除错误信息。

The full code snippet can be found here http://codelife.cybtamin.com/enable-and-disable-asp-net-validator-by-javascript/

完整的代码片段可以在这里找到http://codelife.cybtamin.com/enable-and-disable-asp-net-validator-by-javascript/