Chris Conway
Chris Conway

Reputation: 16529

Fire event after client side script validation in asp.net?

Is there a way that I can execute a Javascript function after the client side validation occurs in asp.net?

I have a couple validation controls on a page and an input button with CausesValidation=true. The OnClientClick handler executes Javascript before the validation runs, but i want to run some functions afterwards.

Is this possible?

Upvotes: 7

Views: 3921

Answers (2)

Bharat Ram V
Bharat Ram V

Reputation: 101

Just an enhancement to the above solution (I too used it)

If there are multiple buttons in your form and you want to run the script only after the user clicks on one button, use the document.activeElement.id It retrieves the current focussed element's ID.

Using this you can run your script upon clicking a certain button.

Upvotes: 0

Aristos
Aristos

Reputation: 66649

The ASP.NET calls the WebForm_OnSubmit, thats runs the validation. After validation is ok, its continue and run the rest JavaScript functions that's found on onsubmit on the form.

So to execute a JavaScript after the side validation, just place it on 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>

Upvotes: 3

Related Questions