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?

3 Answers 3

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; }"
Sign up to request clarification or add additional context in comments.

1 Comment

This seems to work, but in fact it print two time the ValidationSummary's ShowMessageBox :(
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.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.