javascript Page_ClientValidate 返回 false 但没有一个验证器有错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10169623/
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
Page_ClientValidate returns false but none of the validators have errors
提问by Rajbir Singh
I am using Page_ClientValidate for validations.
我正在使用 Page_ClientValidate 进行验证。
It returns false even there is no invalid inputs.
即使没有无效输入,它也会返回 false。
function PageValid() {
var valid = Page_ClientValidate('save');
alert(valid);
if (valid == true) {
$('.mydiv').hide();
}
}
Here 'save' is the validation group. Please help me guys.
这里的“保存”是验证组。请帮帮我。
Thanks, Rajbir
谢谢,拉吉比尔
回答by Niranjan Singh
Go through ASP.NET Validation in Depthand Java script page validation Page_clientValidate()
通过ASP.NET 深度验证和Java 脚本页面验证 Page_clientValidate()
The Job of this function is to check the page is it valid if any of the validator is not valid this function return false otherwise it return true.
此函数的工作是检查页面是否有效,如果任何验证器无效,则此函数返回 false 否则返回 true。
if (Page_ClientValidate()) {
// Page is Ok
//Submit it To The Server
return true
} else {
//Page is Not Valid
//Return False
return false
}
It may possible that you are missing about validation settings on your validator or some other error on js.
您可能缺少验证器上的验证设置或 js 上的其他一些错误。
You can do manual validation as:
您可以进行手动验证:
<script type="text/javascript" language="javascript">
/* Manual client-side validation of Validator Groups */
function fnJSOnFormSubmit() {
var isGrpOneValid = Page_ClientValidate("valGrpOne");
var isGrpTwoValid = Page_ClientValidate("valGrpTwo");
var i;
for (i = 0; i < Page_Validators.length; i++) {
ValidatorValidate(Page_Validators[i]); //this forces validation in all groups
}
//display all summaries.
for (i = 0; i < Page_ValidationSummaries.length; i++) {
summary = Page_ValidationSummaries[i];
//does this summary need to be displayed?
if (fnJSDisplaySummary(summary.validationGroup)) {
summary.style.display = ""; //"none"; "inline";
}
}
if (isGrpOneValid && isGrpTwoValid)
return true; //postback only when BOTH validations pass.
else
return false;
}
Ref:
Page_ClientValidate() with multiple ValidationGroups - how to show multiple summaries simultaneously?
Page_ClientValidate is validating multiple times.
参考:
Page_ClientValidate() 与多个 ValidationGroups - 如何同时显示多个摘要?
Page_ClientValidate 正在验证多次。