Search

The Old Confirm Button Trick

1 views

You have probably at some point clicked the wrong input button on a web page, and something bad happened. You deleted the wrong user, submitted to the wrong newsletter or something similar. Wouldn't it have been nice if you had been asked to confirm a critical decision like that? In ASP.NET it is so easy to create functionality around post backs caused by input buttons or similar click-controls. This is also the reason why it is important to let the user confirm actions to avoid mistakes. I remember this exact issue when I started in ASP.NET 4 years ago. Back then I did some silly things in order to make the proper confirmation functionality, but hey, it worked. Of course, I had to find the easiest way, and I believe I did. I have used this simple exercise for all of my web projects, simply because it is the simplest and best way to do it. It mixes a regular ASP.NET button control with the JavaScripts confirm dialog. Here's how it looks like when you click the button.

And the much easier way in ASP.NET 2.0 <asp:Button Runat="server" ID="btnConfirm" Text="Confirm" OnClientClick="return confirm('Are you sure you want to click the button?');" /> And finally the old fashion HTML way <input type="submit" value="Confirm" onclick="return confirm('Are you sure you want to click the button?');" /> There is nothing fancy about this little trick, but it may help you do it a little easier. I for one could have used this trick a couple of years ago. Enjoy. Tag: Add to Del.icio.us | Digg | Reddit | Furl Bookmark Murdok: Mads Kristensen currently works as a Senior Developer at Traceworks located in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in 2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and web services in his daily work as well. A true .NET developer with great passion for the simple solution.

http://www.madskristensen.dk/

Suggest a Correction

Found an error or have a suggestion? Let us know and we'll review it.

Share this article

Comments (0)

Please sign in to leave a comment.

No comments yet. Be the first to comment!