使用jQuery的用户界面对话框,使用ASP一个确认对话框:LinkButton的(如何调用postbck) [英] Using jquery-ui dialog as a confirm dialog with an ASP:LinkButton (how to invoke the postbck)
问题描述
我想使用jQuery UI的对话框来实现它显示一个确认对话框,当用户点击删除链接(使用 ASP执行:LinkButton的
)。结果
我使用code如下所示(复制从jQuery UI的文档):
I'd like to use jQuery UI's dialog to implement a confirm dialog which is shown when the user clicks a delete-link (implemented using an asp:LinkButton
).
I'm using code as shown below (copied from the jquery ui documentation):
<!-- 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>
所以在点击
事件处理程序,我不得不prevent的默认操作的的LinkButton
(回发),而是显示该对话框。
So in the click
event handler, I have to prevent the default action of the LinkButton
(the postback) and instead display the dialog.
我的问题是:我怎么能然后调用删除链接的默认操作(回发)来执行的情况下,用户在对话框中点击删除所有条目按钮,回发
My question is: how can I then invoke the default action (the postback) of the delete link to perform the postback in case the user clicked the "Delete all items" button in the dialog?
推荐答案
OK,这里是我的方法(它的工作原理,但它可能不是最好的解决方案):
OK, here's my approach (it works, but it might not be the best solution):
$(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;
});
});
这篇关于使用jQuery的用户界面对话框,使用ASP一个确认对话框:LinkButton的(如何调用postbck)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!