Page_ClientValidate返回false,但没有一个验证器有错误

时间:2012-04-16 06:31:22

标签: javascript asp.net

我正在使用Page_ClientValidate进行验证。

即使没有无效输入,也会返回false。

  function PageValid() {

            var valid = Page_ClientValidate('save');

            alert(valid);

            if (valid == true) {

                $('.mydiv').hide();
            }

        }

此处'save'是验证组。请帮帮我们。

谢谢, Rajbir

1 个答案:

答案 0 :(得分:13)

浏览ASP.NET Validation in DepthJava script page validation Page_clientValidate()

  

此功能的作业是检查页面是否有效(如果有的话)   验证器无效此函数返回false,否则返回false   返回true。

if (Page_ClientValidate()) {

// Page is Ok

//Submit it To The Server

return true
} else {

//Page is Not Valid

//Return False

return false

}

您可能遗漏了验证器上的验证设置或js上的其他错误。

您可以进行手动验证:

<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;
    }

价:
Page_ClientValidate() with multiple ValidationGroups - how to show multiple summaries simultaneously?
Page_ClientValidate is validating multiple times.