In an aspx page, there is an asp:linkbutton like this:
<asp:LinkButton runat="server" ID="btExit" Text="Exit"
OnClientClick="javascript:return confirmExit();"
EnableViewState="false"
OnClick="ExitButtonClick"></asp:LinkButton>
And this is the javascript function:
<script type="text/javascript">
function confirmExit() {
bootbox.confirm("Are you sure?", function (confirmed) {
return confirmed;
});
}
</script>
The problem is that, as far as I know, bootbox.confirm works asynchronously, and ExitButtonClick function on code behind is executed without waiting for the user confirmation.
I found a solution that works, using a hidden button:
<asp:LinkButton runat="server" ID="btExit" Text="Exit"></asp:LinkButton>
<asp:Button runat="server" ID="btExitHidden" onclick="ExitButtonClick" style="display:none;" />
And this is the javascript part:
<script type="text/javascript">
$("#btExit").click(function (e) {
e.preventDefault();
bootbox.confirm("Are you sure?", function (confirmed) {
if (confirmed) {
$("#btExitHidden").click();
}
});
});
</script>
My question is if there is a more "beautiful" and "standard" way to work synchronously with a Bootbox.confirm, without using a hidden button.