locked
window.confirm RRS feed

  • Question

  • User911902078 posted

    Hi,

    i have a button which has an attribute which is shown below 

    del_cat.Attributes.Add("onclick", "window.confirm('Are you sure you want to delete the category')")

    i want to the answer of the window.confirm and i dont know the code for it.

    plz help

    Friday, December 28, 2007 8:12 PM

Answers

  • User798903548 posted

    Change the attribute to:
         del_cat.Attributes.Add("onclick", "return window.confirm('Are you sure you want to delete the category');")

    Then the server-side button handler will only be called if OK is answered.

    NC...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, December 29, 2007 6:49 AM
  • User798903548 posted

    Where are you attaching the event handler (.Attributes.Add(...)? This should be done in Page_Load, whether a PostBack or not.

    NC...

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 30, 2007 6:36 AM

All replies

  • User-2005691517 posted

     Confirm returns the value 1 if the user clicks OK and the value 0 if the user clicks Cancel. As such, you can use the return value directly as a boolean

    if( confirm(....))
    {

    //do something 

    Friday, December 28, 2007 8:48 PM
  • User798903548 posted

    Change the attribute to:
         del_cat.Attributes.Add("onclick", "return window.confirm('Are you sure you want to delete the category');")

    Then the server-side button handler will only be called if OK is answered.

    NC...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, December 29, 2007 6:49 AM
  • User-861818263 posted

     

    Ok i am removing it I have not seen your post.i read question and give the answer to it ok sorry

    Saturday, December 29, 2007 7:08 AM
  • User798903548 posted

    del_cat.Attributes.Add("onclick", "javascript:return window.confirm('Are you sure you want to delete the category')")

    Funny looks exactly like my post except that you added the "javascript" which is not really necessary.

    NC...

     

    Saturday, December 29, 2007 7:19 AM
  • User-861818263 posted

     Ok i am removing it I have not seen your post.i read question and give the answer

    ok sorry

    Saturday, December 29, 2007 7:32 AM
  • User911902078 posted

    Hi,

    The confirm box only appears when i press the button twice

    Sunday, December 30, 2007 6:16 AM
  • User798903548 posted

    Where are you attaching the event handler (.Attributes.Add(...)? This should be done in Page_Load, whether a PostBack or not.

    NC...

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 30, 2007 6:36 AM
  • User911902078 posted

    Hi,

    Ohh okay i was puttin it somewhere else

     

    Monday, December 31, 2007 11:10 AM