javascript – 传递ASP.NET按钮单击SweetAlert中的事件

我有一个C#方法执行挂起操作.

 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);
        }

    }

我现在正在使用BootBox

$('#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 %>", "");
                }

            });
        });

这是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"); 
});

我怎样才能让它像BootBox一样工作?就像在BootBox中一样,当我按下SuspendButton时,它会抛出一个bootbox.confirm弹出窗口,如果我按下O,K就会执行基础操作.我可以用SweetAlert做同样的事情吗?

最佳答案 您可以尝试这样的事情,如果这不是您想要的,请告诉我

$('#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();   }
        });    
  });
点赞