Yes, believe it or not I am going to write an on-topic post on my blog. Not only that but a programming post even, shocking I know. But I had a particular problem today and I thought the solution was worth sharing.
So I had a form, fairly simple form, a handful of textboxes and dropdown boxes and a submit button. I had some validation controls on there to ensure that the data was entered correctly and the form was working fine. I decided to add a confirmation message to the onclientlclick event of the submit button. You know the sort of thing, a popup button that says “Are you sure you want to perform this action” with an ok and cancel button. So I added the following code to the onclientlclick property of the button.
return confirm('Are you sure you want to perform this action?')
This had an unexpected result, when you click ok on the popup window, it ignored all of the form validation controls and submitted the form whatever was filled in. Well after much digging around google, I found the following solution. You need to wrap the javascript in an if statement and check the Page_ClientValidate property. So all you need to do is replace the code in the onclientlclick property with the following.
if (Page_ClientValidate()){return confirm('Are you sure you want to perform this action?')}
This now works perfectly, the popup doesn’t even appear unless all of the validation requirements have been met. A useful little piece of javascript I though, hope it will be of some use to you.
My blog is mainly about programming in .Net 2, website promotion and affiliate marketing although I do have the odd ramble on about anything that comes to mind.


June 7th, 2007 at 3:41 am
Steve: I found this and thought it might be useful to you. Or at the very least, interesting. http://www.blogherald.com/2007/06/07/forcing-www-in-the-url-helps-dig-you-out-of-googles-supplemental-index/
July 9th, 2007 at 9:01 am
Just wanted to say thank you. I really needed this.
July 9th, 2007 at 1:34 pm
Your welcome Aaron, glad my post was of some help to you.
September 7th, 2007 at 3:47 pm
This really helped me a LOT and I was searching for it for a LONG time! Thank for the tutorial….
September 8th, 2007 at 5:26 am
Always happy to have helped a fellow programmer Michael.
February 28th, 2008 at 3:18 pm
Thanks a lot, I searched for a while till I finally found your great hint, saved my day
Cheers,
Oliver