I found a JQuery Alert plugin here, http://www.abeautifulsite.net/blog/2008/12/jquery-alert-dialogs/
So I made a sample page to test it out but it does not seem to work on Runat=”server” button. The second button is just something I tried to stop the button from posting back and it seems to do that but after confirming, it won’t go anywhere.
I would appreciate any help on this.
<script src="js/jquery.alerts.js" type="text/javascript"></script>
<link href="css/jquery.alerts.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript">
function confirmThis() {
jConfirm('Can you confirm this?', 'Confirmation Dialog', function (r) {
jAlert('Confirmed: ' + r, 'Confirmation Results');
return r;
});
return false;
}
$(document).ready(function () {
$("#btnNext").click(function () {
jConfirm('Can you confirm this?', 'Confirmation Dialog', function (r) {
jAlert('Confirmed: ' + r, 'Confirmation Results');
return r;
});
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnNext" runat="server" Text="Confirm 1"/>
<asp:Button ID="Button1" runat="server" Text="Confirm 2" OnClientClick="return confirmThis();"/>
</div>
</form>
</body>
</html>
While you should use
btnNext.ClientID, that’s not the cause of your problem here. The problem is that the library you are using makes use of callbacks to implement the confirm popup, which means that the function you are attaching to theclickevent does not wait for the confirm dialog to be clicked before exiting. Sincefalseis not returned from that function, the button click is not cancelled and a postback occurs.See the accepted answer here for more information:
Can you wait for javascript callback?
One way around this problem is to always return false, and then in the callback from the confirm click the button. Keep in mind you’ll have to
unbindthe event handler before callingclickmanually. The following code worked for me: