Using bootbox.confirm with .NET web forms

335 views Asked by At

I am trying to work with web forms. I have basic knowledge only (I mainly work with MVC).

<asp:Button runat="server" ID="LinkButton1" OnClientClick="return confirmItemDelete()" CommandArgument='<%# Eval("id") %>' Text="Delete" OnClick="lbDeleteMessage_Click"></asp:Button>

function confirmItemDelete() {
            bootbox.confirm('Are you sure you want to delete this message?',
                function (confirmed) {
                    return confirmed;
                });            
        };

Button click always causes server side Delete. This is because bootbox.confirm works with callbacks (return false or true only in callback). This causes always run server side postback.

What is the best solution here?

1

There are 1 answers

0
Jedsada Saengow On

You can use other html control for call bootbox and use javascript call <asp:Button /> for click in callback.

HTML

<asp:Button ID="linkLogout" Style="display: none;" OnClick="linkLogout_Click" runat="server" />

<div style="padding: 3px; cursor: pointer;" onclick="showConfirm('Alert', 'Are you want to logout ?')">Logout</div>

Javascript

 function showConfirm(title, msg) {
     bootbox.confirm({
          title: title,
          message: msg,
          buttons: {
               confirm: {
                    label: 'Yes',
                    className: 'btn-primary'
               },
               cancel: {
                    label: 'No',
                    className: 'btn-default'
               }
          },
          callback: function (result) {
               if (result) {
                    $('#linkLogout').click();
               }
          }
   });
}