2016-04-29 48 views
4

我有一個C#方法,它執行掛起操作。傳遞ASP.NET按鈕單擊SweetAlert中的事件

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 ?

回答

1

你可以嘗試這樣的事情,讓我知道這是不是你想要

$('#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(); } 
     });  
    }); 
+0

謝謝先生。它的工作。這就是我想要的。你爲我的生活節省了一些時間。:) – OLDMONK

0

嘗試這個東西,所有的 首先把你的甜蜜,報警代碼在一些功能讓說「暫停()」 例如:

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()」 例如分配功能名稱