views:

22

answers:

1

So basically I want to add a javascript function to a button's Click event and I only want it to execute if the form passes ASP.NET client-side validation.

The easiest conceptual way I can think of is to just run the validation within my function just return if it doesn't pass, but I'm not sure how to call ASP.NET's validators from javascript.

The other way I can think of is maybe set a flag when the button is clicked, then hook into an event after the validation occurs (not sure if this is possible or how to do so) and run the function if the button click flag was set. There is more than 1 button that causes validation which is why the flag is needed rather than just assuming the button was clicked if validation happened.

Also open to alternative ideas.

(Using MooTools as our JS library if that matters)

+2  A: 

I'd say to just go ahead and attach the function to the button's click event, but then invoke the ASP.NET validation using the following function call:

Page_ClientValidate();

It should return true if the page was valid.

GotDibbs
Perfect, just didn't know what it was called.
Davy8