我想使用 jQuery UI 的对话框来实现用户单击删除链接时显示的确认对话框(使用 asp:LinkButton
实现)。
我正在使用如下所示的代码(从 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
事件处理程序中,我必须阻止 LinkButton
(回发)的默认操作,而是显示对话框。
我的问题是:如果用户单击对话框中的“删除所有项目”按钮,我如何才能调用删除链接的默认操作(回发)来执行回发?
最佳答案
好的,这是我的方法(可行,但可能不是最佳解决方案):
$(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/