
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.
Similar Posts
« Looking in totally the wrong place for an error SQL Server 2005: Selecting Records From One Table That Do Not Exist In Another »

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/
Just wanted to say thank you. I really needed this.
Your welcome Aaron, glad my post was of some help to you.
This really helped me a LOT and I was searching for it for a LONG time! Thank for the tutorial….
Always happy to have helped a fellow programmer Michael.
thanks – saved me
Thanks this worked for me.
Wow, Thanks for the post.
Thanx it worked fine for me. I appreciate
Thanj you very much. This is what i was searching.
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.
Awesome man….gr8 help
I spend some 2 hours googling this …thanks a lot
Your very welcome, I know how it is when you spend hours digging for a solution to something.
It’s work. Thank you very much
Hi Steve, This was very helpful. Saved a lot of my time.. Thanks
!!