在.NET Web表单中使用bootbox.confirm

问题描述 投票:0回答:1

我正在尝试使用Web表单。我只有基础知识(我主要使用MVC)。

<asp:Button runat="server" ID="LinkButton1" OnClientClick="return confirmItemDelete()" CommandArgument='<%# Eval("id") %>' Text="Delete" OnClick="lbDeleteMessage_Click"></asp:Button>

function confirmItemDelete() {
            bootbox.confirm('Are you sure you want to delete this message?',
                function (confirmed) {
                    return confirmed;
                });            
        };

按钮单击总是导致服务器端删除。这是因为bootbox.confirm使用回调(仅在回调中返回false或true)。这会导致始终运行服务器端回发。

这里最好的解决方案是什么?

.net webforms bootbox
1个回答
0
投票

您可以使用其他html控件来调用bootbox并使用javascript调用<asp:Button />来单击回调。

HTML

<asp:Button ID="linkLogout" Style="display: none;" OnClick="linkLogout_Click" runat="server" />

<div style="padding: 3px; cursor: pointer;" onclick="showConfirm('Alert', 'Are you want to logout ?')">Logout</div>

使用Javascript

 function showConfirm(title, msg) {
     bootbox.confirm({
          title: title,
          message: msg,
          buttons: {
               confirm: {
                    label: 'Yes',
                    className: 'btn-primary'
               },
               cancel: {
                    label: 'No',
                    className: 'btn-default'
               }
          },
          callback: function (result) {
               if (result) {
                    $('#linkLogout').click();
               }
          }
   });
}
© www.soinside.com 2019 - 2024. All rights reserved.