asp.net - 使用 jquery-ui 对话框作为 ASP :LinkButton (how to invoke the postbck) 的确认对话框

标签 asp.net jquery-ui jquery-ui-dialog webforms

我想使用 jQuery UI 的对话框来实现用户单击删除链接时显示的确认对话框(使用 asp:LinkBut​​ton 实现)。
我正在使用如下所示的代码(从 jquery ui 文档中复制):

<!-- the delete link -->
<asp:LinkButton ID="btnDelete" runat="server" Text="Delete"
  OnClick="btnDelete_Click" CssClass="btnDelete"></asp:LinkButton>

<!-- the confirm-dialog -->
<div id="dialog-confirm-delete" title="Delete?" style="display:none;">
  <p>Are you sure you want to permanently deleted the selected items?</p>
</div>

<script>
$(document).ready(function () {
    // setup the dialog
    $('#dialog-confirm-delete').dialog({
        autoOpen: false,
        modal: true,
        buttons: {
          "Delete all items": function () {
                 $(this).dialog("close");
                 // ===>>> how to invoke the default action here
              },
          Cancel: function () { $(this).dialog("close"); }
        }
    });

    // display the dialog
    $('.btnDelete').click(function () {
        $('#dialog-confirm-cancel').dialog('open');
        // return false to prevent the default action (postback)
        return false;
    });

});
</script>

所以在 click 事件处理程序中,我必须阻止 LinkBut​​ton(回发)的默认操作,而是显示对话框。

我的问题是:如果用户单击对话框中的“删除所有项目”按钮,我如何才能调用删除链接的默认操作(回发)来执行回发?

最佳答案

好的,这是我的方法(可行,但可能不是最佳解决方案):

$(document).ready(function () {
  $('#dialog-confirm-cancel').dialog({
    autoOpen: false,
    modal: true,
    buttons: {
      "Delete all items": function () {
        // invoke the href (postback) of the linkbutton,
        // that triggered the confirm-dialog
        eval($(this).dialog('option', 'onOk'));
        $(this).dialog("close");
      },
      Cancel: function () { $(this).dialog("close"); }
    }
  });

  $('.btnDelete').click(function () {
    $('#dialog-confirm-delete')
      // pass the value of the LinkButton's href to the dialog
      .dialog('option', 'onOk', $(this).attr('href'))
      .dialog('open');
    // prevent the default action, e.g., following a link
    return false;
  });
});

关于asp.net - 使用 jquery-ui 对话框作为 ASP :LinkButton (how to invoke the postbck) 的确认对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4133994/

相关文章:

jquery-ui - jQuery UI 对话框 : vertical scroll works not correct if dialog height more than window height

jquery - jquery 对话框打开时窗口向上滚动

jquery-ui - 在 droppable 的 Drop 事件上调用 $(item).sortable ('cancel' ) 禁用可排序

javascript - 如何使用局部 View 展开/折叠 html 表格?

asp.net - Internet Explorer 11 在 PageRequestManager.js 中出现脚本错误

c# - 在 ASP.NET MVC 应用程序中重写 ResourceManager?

jQuery UI Datepicker 月份和年份组合在 jQuery BlockUI(弹出)中不起作用

jQuery : add title to jquery data table( retrieving from server side)

jquery - 如何通过 Jquery 对话框小部件使用缓动

c# - iTextSharp 中 HTMLWorker 的 Stack Empty 异常