Finally found how to display confirm dialog box

T

Tony Baker

Wow. I finally found out the easiest way to display a yes/no (well,
yes/cancel) dialog pop up from ASP.Net.
Turnes out to be really easy. Just add the following in you Page_Load
method (C# code behind):

if(!IsPostBack)
{
DeleteUserBtn.Attributes.Add("onclick", "return confirm('Are you sure
you want to Delete?')");
}

Replace DeleteUserBtn with the name of your asp.net button (or
whatever control you want).

This will assign javaScript to that button to return the result of
displaying the confirm dialog. If user clicks yes, then it returns
true and the buttons code-behind method will be called. Otherwise a
post-back won't occur and the code-behind will not be run!!

This method can be used to call any javaScript function you may have
already defined.

I hope someone can find this info useful and it saves someone some
time.

Tony.

P.S. If you are writing an ASP.Net program and you don't know
JavaScript, you are limiting yourself a lot! Spend an 30 mins or so
doing this tutorial to give yourself some idea of the power it can
provide:
http://www.w3schools.com/js/default.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top