2

i have a validationSummary in my page. i want to call a javascript function after the validationSummary is filled. how can i achieve this?

i think i should add an attribute in the code behind, but i can't figure out what is the attribute's key.

any help?

july
  • 21
  • 1
  • 2

3 Answers3

4

You will want to call the javascript function Page_ClientValidate() to initiate the ASP.NET validation wired to your page controls. Once this is called, the Page_IsValid boolean value will be properly set.

Here is an example of how I am using it. If ASP.NET validation is successful, I disable the button, otherwise the button remains enabled and the validation summary is displayed to the user. The OnClientClick is from a ASP:Button control.

OnClientClick="javascript:Page_ClientValidate(); if (Page_IsValid==true) { this.disabled=true; }"
takrl
  • 6,356
  • 3
  • 60
  • 69
0

I started to implement the solution by @EverettEvola but also where the validation logic was being called multiple times and displaying multiple ValidationSummary popups. My solution was as follows:

On the button (in my case the button was a submit button)

OnClientClick="return CustomValidationOnClick()"

And the CustomValidationOnClick()

function CustomValidationOnClick(source, args) {

    //Manually kickoff page validation
    //This call will display the Validation summary popup if page is invalid
    Page_ClientValidate();

    //Page_IsValid set by the result of the Page_ClientValidate() call
    if (Page_IsValid == true) {
        this.disabled=true;
        return true; //if Submit button return true to continue form submit
    }
    else {
       //do whatever here
       return false; //if Submit button return false to cancel form submit
    }
}
MoMo
  • 8,149
  • 3
  • 35
  • 31
0

I don't think that's possible. It is, however, possible to intercept validation by setting OnClientClick on the controls that do postbacks. Then you can check the global JavaScript variable Page_IsValid for the validation result.

One thing to keep in mind is that, when there are no validators on a page, Page_IsValid will be undefined.

ErikHeemskerk
  • 1,623
  • 14
  • 30