
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.

Subscribe to blog via RSS Feed
Follow Me On Twitter
steve said,
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/
Aaron Hardy said,
Just wanted to say thank you. I really needed this.
Steve Kinsey said,
Your welcome Aaron, glad my post was of some help to you.
Michael Samuel said,
This really helped me a LOT and I was searching for it for a LONG time! Thank for the tutorial….
Steve Kinsey said,
Always happy to have helped a fellow programmer Michael.
Matthew said,
thanks – saved me
Vinod said,
Thanks this worked for me.
Bernard said,
Wow, Thanks for the post.
Dumisani said,
Thanx it worked fine for me. I appreciate
rspaz said,
Thanj you very much. This is what i was searching.
Seth Rogan said,
Have you ever considered adding more videos to your blog posts to keep the readers more entertained? I mean I just read through the entire article of yours and it was quite good but since I’m more of a visual learner,I found that to be more helpful well let me know how it turns out! I love what you guys are always up too. Such clever work and reporting! Keep up the great works guys I’ve added you guys to my blogroll. This is a great article thanks for sharing this informative information.. I will visit your blog regularly for some latest post.
Add A Comment