Get confirmation from popup before running code in event handler

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like the code in the click event handler of an ImageButton to run only after a popup confirm appears and the user clicks its 'OK'. The 'CauseValidation' property of the ImageButton is 'true'
 
Place this in the Page_Load event. Note that the first parameter of the Add
method is the JavaScript "onclick" event and the second parameter is a
JavaScript statement.

ImageButton1.Attributes.Add("onclick", "if (!confirm('Are you sure?'))
return false;");

mg said:
I would like the code in the click event handler of an ImageButton to run
only after a popup confirm appears and the user clicks its 'OK'. The
'CauseValidation' property of the ImageButton is 'true'
 
This is mostly an academic question....
I agree this will work in this instance. However, is there a way to
tell/specify what order the events will fire when you have a bunch of them?
 
What do you mean "a bunch of them"? Events such as the Javascript one
described below will happen first, as this will prevent the postback from
taking place unless confirmed. On the server side, the page load event will
always fire first, then the onclick event.
 
Back
Top