簡體   English   中英

傳遞ASP.NET按鈕單擊SweetAlert中的事件

[英]Passing An ASP.NET Button Click Event in 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();   }
        });    
  });

試試這個,首先把你的甜蜜警報代碼放在某個函數中讓我們說'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" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM