Finally found how to display confirm dialog box

Discussion in 'ASP .Net' started by Tony Baker, Dec 17, 2003.

  1. Tony Baker

    Tony Baker Guest

    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
     
    Tony Baker, Dec 17, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Grey
    Replies:
    7
    Views:
    13,655
    Greg Burns
    Sep 7, 2004
  2. David Lozzi

    Try...Catch...Finally not firing finally?

    David Lozzi, Apr 23, 2007, in forum: ASP .Net
    Replies:
    12
    Views:
    823
    Alvin Bruney [MVP]
    May 11, 2007
  3. =?Utf-8?B?UmFq?=

    Script Manager - Confirm dialog box

    =?Utf-8?B?UmFq?=, May 18, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    2,933
    Thomas Hansen
    May 18, 2007
  4. Marc

    Confirm dialog box

    Marc, Feb 6, 2004, in forum: Javascript
    Replies:
    1
    Views:
    134
    kaeli
    Feb 6, 2004
  5. Matt
    Replies:
    1
    Views:
    305
    Randy Webb
    Nov 20, 2004
Loading...

Share This Page