M4N*_*M4N 2 asp.net webforms jquery-ui jquery-ui-dialog
我想使用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>
Run Code Online (Sandbox Code Playgroud)
所以在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;
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5035 次 |
| 最近记录: |