7

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?

0

2 Answers 2

3

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

Comments

0

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.

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.