If you want to show the fancier modal dialog, you can use the jQuery dialog widget. To fit your example, check out the following code for the body element of a sample web form:
<form id="form1" runat="server"> <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /> <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" /> <div id="deleteConfirmationDialog" title="Warning!">Are you sure you want to delete?</div> <asp:Button ID="_btnDelete" runat="server" Text="Delete" OnClick="_btnDelete_ServerClick" OnClientClick="return _btnDelete_ClientClick();" /> </form> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script> <script type="text/javascript"> function doPostBack(theForm, eventTarget, eventArgument) { if (!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); } } function showConfirmationDialog(dialogSelector, callback, form, target) { $(dialogSelector).dialog({ resizable: false, height: 200, modal: true, buttons: [{ text: "Yes", click: function () { $(this).dialog("close"); callback(form, target, null); } }, { text: "No", click: function () { $(this).dialog("close"); } }] }); }; function _btnDelete_ClientClick() { showConfirmationDialog("#deleteConfirmationDialog", doPostBack, $("#form1").get(0), "_btnDelete"); return false; } $(document).ready(function () { $("#deleteConfirmationDialog").hide(); }); </script>
The code associated with the _btnDelete control (the _btnDelete_ServerClick method) will only be executed if you click the Yes button in the modal dialog box after clicking the Delete button. Remember to add the jQuery UI CSS file to the chapter section:
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery.ui.all.css"/>
source share