Confirmation Message

Discussion in 'ASP .Net' started by Dave, Oct 2, 2004.

  1. Dave

    Dave Guest

    Hello.
    I want to prompt user for some action with Yes/No message, I know some
    tricks in JavaScript, but I need to handle the user answer at server side.
    Exactly I want to prompt user for confirmation on delete action of some data
    in my application.
    How can I do this?
     
    Dave, Oct 2, 2004
    #1
    1. Advertising

  2. Dave

    Sahil Malik Guest

    If you look in the generated html out of an asp.net page, it contains a
    form, and that form is submitted by a standard javascript function. You need
    to write your custom javascript that ends up calling that javascript
    function (which then does the postback).

    Hope that helped.

    - Sahil Malik
    You can reach me thru my blog -
    http://www.dotnetjunkies.com/weblog/sahilmalik

    "Dave" <> wrote in message
    news:...
    > Hello.
    > I want to prompt user for some action with Yes/No message, I know some
    > tricks in JavaScript, but I need to handle the user answer at server side.
    > Exactly I want to prompt user for confirmation on delete action of some
    > data in my application.
    > How can I do this?
    >
     
    Sahil Malik, Oct 2, 2004
    #2
    1. Advertising

  3. Hi,

    Here is how I would do it. First create your button that launches the
    Yes/No message, then declare it in your code behind. For example:

    Protected WithEvents btnDelete As System.Web.UI.WebControls.Button

    Then add this attribute:

    btnDelete.Attributes.Add("onclick", "return ConfirmDelete();")

    In your ASPX page add this javascript function:

    function ConfirmDelete() {
    boolReturn = confirm("Are you sure you wish to delete this?");
    if (boolReturn)
    return true;
    else
    return false;
    }

    Then create your handler in your code behind to do the deletion for
    btnDelete.

    The attribute you add calls the client side javascript function to confirm
    the user's choice. If the user confirms it, then true is returned which
    will submit the form and run your btnDelete click event. Should the user
    cancel, then false is returned and the form will not post back. Good luck!
    Ken.

    --
    Ken Dopierala Jr.
    For great ASP.Net web hosting try:
    http://www.webhost4life.com/default.asp?refid=Spinlight
    If you sign up under me and need help, email me.

    "Dave" <> wrote in message
    news:...
    > Hello.
    > I want to prompt user for some action with Yes/No message, I know some
    > tricks in JavaScript, but I need to handle the user answer at server side.
    > Exactly I want to prompt user for confirmation on delete action of some

    data
    > in my application.
    > How can I do this?
    >
    >
     
    Ken Dopierala Jr., Oct 2, 2004
    #3
  4. Dave

    Dave Guest

    Can you show me some demo please?

    "Ken Dopierala Jr." <> wrote in message
    news:...
    > Hi,
    >
    > Here is how I would do it. First create your button that launches the
    > Yes/No message, then declare it in your code behind. For example:
    >
    > Protected WithEvents btnDelete As System.Web.UI.WebControls.Button
    >
    > Then add this attribute:
    >
    > btnDelete.Attributes.Add("onclick", "return ConfirmDelete();")
    >
    > In your ASPX page add this javascript function:
    >
    > function ConfirmDelete() {
    > boolReturn = confirm("Are you sure you wish to delete this?");
    > if (boolReturn)
    > return true;
    > else
    > return false;
    > }
    >
    > Then create your handler in your code behind to do the deletion for
    > btnDelete.
    >
    > The attribute you add calls the client side javascript function to confirm
    > the user's choice. If the user confirms it, then true is returned which
    > will submit the form and run your btnDelete click event. Should the user
    > cancel, then false is returned and the form will not post back. Good
    > luck!
    > Ken.
    >
    > --
    > Ken Dopierala Jr.
    > For great ASP.Net web hosting try:
    > http://www.webhost4life.com/default.asp?refid=Spinlight
    > If you sign up under me and need help, email me.
    >
    > "Dave" <> wrote in message
    > news:...
    >> Hello.
    >> I want to prompt user for some action with Yes/No message, I know some
    >> tricks in JavaScript, but I need to handle the user answer at server
    >> side.
    >> Exactly I want to prompt user for confirmation on delete action of some

    > data
    >> in my application.
    >> How can I do this?
    >>
    >>

    >
    >
     
    Dave, Oct 2, 2004
    #4
  5. Hi,

    I don't have a demo, all the code I gave you will work. Just drag a button
    from the toolbox onto your form. Name it btnDelete. Then in your page load
    event put this:

    btnDelete.Attributes.Add("onclick", "return ConfirmDelete();")

    In the <head> section of your HTML put this:

    <script language="javascript">
    function ConfirmDelete() {
    boolReturn = confirm("Are you sure you wish to delete this?");
    if (boolReturn)
    return true;
    else
    return false;
    }
    </script>

    Go back to your code page. Select the btnDelete control from the dropdown
    on the left just above your code and below your tabs. Then in the drop down
    directly to the right select the Click event. Set a break point on the
    first line of the btnDelete_Click() function that is created for you. Now
    run your app.

    When you click the button on your form, a window will popup asking you if
    you want to confirm. If you click OK it will go back to the server and hit
    your break point. If you click Cancel, the confirmation will disappear and
    nothing will happen. Good luck! Ken.

    --
    Ken Dopierala Jr.
    For great ASP.Net web hosting try:
    http://www.webhost4life.com/default.asp?refid=Spinlight
    If you sign up under me and need help, email me.

    "Dave" <> wrote in message
    news:...
    > Can you show me some demo please?
    >
    > "Ken Dopierala Jr." <> wrote in message
    > news:...
    > > Hi,
    > >
    > > Here is how I would do it. First create your button that launches the
    > > Yes/No message, then declare it in your code behind. For example:
    > >
    > > Protected WithEvents btnDelete As System.Web.UI.WebControls.Button
    > >
    > > Then add this attribute:
    > >
    > > btnDelete.Attributes.Add("onclick", "return ConfirmDelete();")
    > >
    > > In your ASPX page add this javascript function:
    > >
    > > function ConfirmDelete() {
    > > boolReturn = confirm("Are you sure you wish to delete this?");
    > > if (boolReturn)
    > > return true;
    > > else
    > > return false;
    > > }
    > >
    > > Then create your handler in your code behind to do the deletion for
    > > btnDelete.
    > >
    > > The attribute you add calls the client side javascript function to

    confirm
    > > the user's choice. If the user confirms it, then true is returned which
    > > will submit the form and run your btnDelete click event. Should the

    user
    > > cancel, then false is returned and the form will not post back. Good
    > > luck!
    > > Ken.
    > >
    > > --
    > > Ken Dopierala Jr.
    > > For great ASP.Net web hosting try:
    > > http://www.webhost4life.com/default.asp?refid=Spinlight
    > > If you sign up under me and need help, email me.
    > >
    > > "Dave" <> wrote in message
    > > news:...
    > >> Hello.
    > >> I want to prompt user for some action with Yes/No message, I know some
    > >> tricks in JavaScript, but I need to handle the user answer at server
    > >> side.
    > >> Exactly I want to prompt user for confirmation on delete action of some

    > > data
    > >> in my application.
    > >> How can I do this?
    > >>
    > >>

    > >
    > >

    >
    >
     
    Ken Dopierala Jr., Oct 2, 2004
    #5
  6. Dave

    Mark Rae Guest

    You don't actually need a Javascript function in the header for this:

    btnDelete.Attributes.Add("onclick", "return confirm('Are you sure you want
    to delete this record?');");

    will work just as well
     
    Mark Rae, Oct 2, 2004
    #6
  7. Thanks Mark!

    Use what Mark has said, it will be much easier! If you ever need to do more
    on the client based on a decision then consider what I posted. But to get
    you up and running fast this is the way to go! Ken.

    "Mark Rae" <> wrote in message
    news:%...
    > You don't actually need a Javascript function in the header for this:
    >
    > btnDelete.Attributes.Add("onclick", "return confirm('Are you sure you want
    > to delete this record?');");
    >
    > will work just as well
    >
    >
     
    Ken Dopierala Jr., Oct 2, 2004
    #7
    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. Ron Clarke

    How to show Confirmation message box?

    Ron Clarke, Jan 15, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    9,387
    Steve C. Orr [MVP, MCSD]
    Jan 15, 2004
  2. Al Cadalzo

    PopUp a confirmation message

    Al Cadalzo, Jun 15, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    4,431
  3. bienwell
    Replies:
    7
    Views:
    121,870
    Vangi
    Aug 4, 2009
  4. Tatyana
    Replies:
    2
    Views:
    505
    Tatyana
    Aug 25, 2006
  5. =?Utf-8?B?YnJpYW5wbWNjdWxsb3VnaA==?=

    disable button after confirmation message

    =?Utf-8?B?YnJpYW5wbWNjdWxsb3VnaA==?=, Oct 20, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    578
    =?Utf-8?B?YnJpYW5wbWNjdWxsb3VnaA==?=
    Oct 21, 2006
Loading...

Share This Page