Stefan Pienaar
I would love to change the world, but they won't give me the source code

ASP.net Popup dialog

March 15, 2007 19:22 by StefanPienaar

Lets face it, there are plenty of people who can hardly get around windows without breaking something, let alone surf the net.

I found a nice little article which shows you how to add a popup dialog to your asp.net buttons. Original Article

This way, if a user accidentally presses the "delete" button (or whatever the case may be) he will be prompted to confirm his action.

Add this piece of javascript between the <head> tags of your page (remember to place it between <script> tags):

function confirmDelete()
{
    return confirm("Are you sure you want to delete this post?");
}

and then this piece of code in your page load event:

myButton.Attributes.Add("onclick", "return confirmDelete();");

Just remember to replace "myButton" with your own button's name. So what happens? When the user click the button, the client side script is executed and the user it prompted to either accept or reject his action. Your button's server side event will only fire if he chooses to continue.

Thanks to David Hayden for the easy to understand and useful article.


Categories: .net
Actions: E-mail | Permalink | Comments (0)