Fire event after confirming client script in asp.net?

Is there a way I can execute the javascript function after checking on the client side in asp.net?

I have several validation controls on the page and an input button with CausesValidation = true. The OnClientClick handler executes javascript before starting the validation, but I want to run some functions afterwards.

Is it possible?

Thanks!

+6
javascript javascript-events validation
source share
2 answers

ASP.NET calls WebForm_OnSubmit , which performs the validation. Once the validation is correct, continue it and run the rest of the JavaScript functions found in the onsubmit form.

So, to execute JavaScript after side validation, just put it in the form tag.

For example:

<script> function CallMeAfterValidation() { // here is the place to run your code return true; } </script> <form onsubmit="return CallMeAfterValidation();" runat="server" ...></form> 
+3
source share

Just an improved solution (I used it too)

If your form has multiple buttons and you want to run the script only after the user clicks on one button, use document.activeElement.id . It retrieves the current item id with focus.

Using this, you can run the script when you click on a specific button.

0
source share

All Articles