Reputation: 21
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?
Upvotes: 2
Views: 3371
Reputation: 8200
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
}
}
Upvotes: 0
Reputation: 51
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; }"
Upvotes: 4
Reputation: 1701
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.
Upvotes: 0