简体   繁体   English

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

[英]Passing An ASP.NET Button Click Event in SweetAlert

I have a C# method which performs a suspend operation. 我有一个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);
        }

    }

I am using BootBox for the same now 我现在正在使用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 %>", ""); } }); }); 

This is the sample of SweetAlert: 这是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"); }); 

How can i make it work like BootBox?Like in BootBox, when i press the SuspendButton, it throws a bootbox.confirm popup, and if i press O,K the underlying operation is performed.Can i do that same with SweetAlert? 我怎样才能让它像BootBox一样工作?就像在BootBox中一样,当我按下SuspendButton时,它会抛出一个bootbox.confirm弹出窗口,如果我按下O,K就会执行基础操作。我可以用SweetAlert做同样的事吗?

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

try this, First of all put your sweet alert code in some function lets say 'Suspend()' eg: 试试这个,首先把你的甜蜜警报代码放在某个函数中让我们说'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"); 
});
}

Now on the .aspx/.cshtml side assign the function name in "onClick()" eg : 现在在.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