Passing ASP.NET Button Click Event to SweetAlert

I have a C # method that performs a pause operation.

 protected void SuspendButton_OnClick(object sender, EventArgs e)
    {
        var accountNumberId = DepositAccount.DepositAccountNumberId;
        var depositAccount = AccountHolders.GetAccountHolder(accountNumberId);

        if (depositAccount == null)
        {
            ShowFailModal("No Account Selected");
        }

        Common.Deposit.AccountSuspension accntSuspension = new Common.Deposit.AccountSuspension();
        accntSuspension.AuditTS = BusinessLayer.Core.DateConversion.GetCurrentServerDate();
        accntSuspension.AuditUserId = UserId;
        accntSuspension.Description = DescriptionTextBox.Text;
        accntSuspension.SuspendedDate = GetDate;
        accntSuspension.AccountNumberId = accountNumberId;

        if (depositAccount != null)
        {
            InsertSuspendedAccount(accntSuspension);
        }

    }

I am using BootBox for the same now

$('#SuspendButton').on('click', function (evt) {
            evt.preventDefault();
            var message = "Are you sure you want to Suspend this Account?";

            bootbox.confirm(message, function (result) {
                if (result === false) {
                    evt.preventDefault();
                } else {
                   // $.showprogress("Account Suspending.Please Wait...");
                    window.__doPostBack("<%= SuspendButton.UniqueID %>", "");
                }

            });
        });
Run codeHide result

This is a sample of SweetAlert:

swal({   title: "Are you sure?",
         text: "You will not be able to recover this imaginary file!",
         type: "warning",   
         showCancelButton: true,   
         confirmButtonColor: "#DD6B55",   
         confirmButtonText: "Yes, delete it!",   
         closeOnConfirm: false 
      },
      function(){  
         swal("Deleted!", "Your imaginary file has been deleted.",        "success"); 
});
Run codeHide result

How can I make it work like a bootbox? Like in BootBox, when I click SuspendButton, it gives a popup window bootbox.confirm, and if I press O, K the basic operation is performed. Can I do the same with SweetAlert

+4
source share
2 answers

You can try something like this, let me know if this is not what you want

$('#SuspendButton').on('click', function (evt) {
           evt.preventDefault();
           //var message = "Are you sure you want to Suspend this Account?";

       swal({   title: "Are you sure?",
            text: "You will not be able to recover this imaginary file!",
            type: "warning",   
            showCancelButton: true,   
            confirmButtonColor: "#DD6B55",   
            confirmButtonText: "Yes, delete it!",   
            closeOnConfirm: false 
            },
            function(isConfirm){   
            if (isConfirm) {     
                // $.showprogress("Account Suspending.Please Wait...");
                window.__doPostBack("<%= SuspendButton.UniqueID %>", "");  
            } else {     
            evt.preventDefault();   }
        });    
  });
+1
source

, , - , , "Suspend()" :

function Suspend()
    {
swal({   title: "Are you sure?",
         text: "You will not be able to recover this imaginary file!",
         type: "warning",   
         showCancelButton: true,   
         confirmButtonColor: "#DD6B55",   
         confirmButtonText: "Yes, delete it!",   
         closeOnConfirm: false 
      },
      function(){  
         swal("Deleted!", "Your imaginary file has been deleted.",        "success"); 
});
}

.aspx/.cshtml "onClick()" :

<input type="submit" value="Suspend" onclick='return Suspend();' title="Suspend" />
0

All Articles