4

I am using Page_ClientValidate for validations.

It returns false even there is no invalid inputs.

  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

Rajbir Singh
  • 1,641
  • 6
  • 23
  • 46

1 Answers1

14

Go through ASP.NET Validation in Depth and Java script page validation 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.

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.

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.

Community
  • 1
  • 1
Niranjan Singh
  • 18,017
  • 2
  • 42
  • 75