Confirm delete with Ajax


Normally we would like to provide a confirmation dialog to the user before deleting something and initiate an AJAX request if user says yes to delete. Standard way looks like this:

<asp:Button ID="Button1" runat="server" OnClientClick="return confirm('Are you sure you want to delete?');" />

To work with AJAX when the button is AJAX-enabled or inside update panel or added to AJAX setting to AjaxManager it needs to be changed a bit.

<asp:Button ID="Button1" runat="server" OnClientClick="if (!confirm('Are you sure?')) return false;" />

So basically with ajax requests, return from javascript cancels the post back it does not matter whether it returns true or false.  So the work around is return only when you want to cancel the post back.

Comments (0)

Skip to main content