【问题标题】:Passing An ASP.NET Button Click Event in SweetAlert在 SweetAlert 中传递 ASP.NET 按钮单击事件
【发布时间】:2016-04-29 05:03:44
【问题描述】:

我有一个执行挂起操作的 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 做同样的事情吗?

【问题讨论】:

    标签: javascript c# jquery asp.net 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();   }
            });    
      });
    

    【讨论】:

    • 谢谢先生。它奏效了。这就是我想要的。你节省了我更多的时间。:)
    【解决方案2】:

    试试这个, 首先将您的甜蜜警报代码放入某个函数中,让我们说“暂停()” 例如:

    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" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-01
      • 2013-05-14
      • 1970-01-01
      • 1970-01-01
      • 2013-08-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多