Validate Page on Submit Before Custom Javascript

by aherrick 12. August 2008 23:55

I was working on form submit where I wanted to prompt with a simple Javascript confirm dialog when the user clicks the submit button on the form.  Naturally, all the form fields (name, adress, etc.) I setup using required field validators.  My custom javascript confirm originally looked like this.

 

I called the javascript from the code behind.

The big problem I found was that the javascript confirm function was being called regardless of if the page completely validated or not.  I wanted the functionality to first validate the page, then if the page was valid, run the custom code.   I came up with this code using Page_IsValid.  It uses Page_ClientValidate() to validate the page, then I check if the page is valid.  Simple yet effective! 

Good luck!

Tags: , , ,



Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen
Tweaked by ajondeck.NET

About the author

Andrew Herrick
I am a full time developer for Blue Horseshoe Solutions based out of Carmel, Indiana. I enjoy learning new technology and hope to give back with some of the cool things I pick up along the way.  Check me out on Stack Overflow!


Categories

None

Recent comments

Comment RSS

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in  anyway.

© Copyright 2008