I've seen other solutions like this one which is pretty straightforward but what if the javascript function does more than just confirm('sure?');
? I never know when it will return a bool.
So I've decided to implement all my ASP.NET Buttons like this:
<button id="btnDelete" name="btnDelete" class="btn">Delete</button>
<asp:Button ID="_btnDelete" runat="server" OnClick="_btnDelete_Click" style="display:none;" />
$('#btnDelete').click(function (e) {
$.blockUI({ message: $('#divConfirmDeleteModal'), overlayCSS: { cursor: 'default' }, css: { cursor: 'default' }, baseZ: 5555 });
return false;
});
$('#btnDeleteYes').click(function () {
$('#<%=_btnDelete.ClientID%>').trigger('click');
});
$('#<%=_btnDelete.ClientID%>').click(function (e) {
// the delay happens here. if i put an alert here, it fires,
// but then the page just loads until eventually the method gets called
<%= ClientScript.GetPostBackEventReference(_btnDelete, string.Empty) %>;
});
..and it's worked well for a while until now. I'm experiencing issues in IE (even version 10) - the _btnDelete_Click
will take up to 2 minutes to get called after clicking the button that ultimately triggers it.
It feels too hacky and I was wondering if there is a better approach.
edit: here is another "correct" way to do it but I want to be able to use a fancier modal dialog and have that return true on a "yes" click, rather than using the browser's native confirm dialog.
edit2: I suppose what I'm asking is, is there a way to return a bool for an OnClientClick function that does more than one thing