Using jquery-ui dialog as a confirm dialog with an ASP:LinkButton (how to invoke the postbck)(使用 jquery-ui 对话框作为带有 ASP:LinkButton 的确认对话框(如何调用 postbck))
问题描述
我想使用 jQuery UI 的对话框来实现一个确认对话框,当用户单击删除链接时显示该对话框(使用 asp:LinkButton 实现).
我正在使用如下所示的代码(从 jquery ui 文档中复制):
<asp:LinkButton ID="btnDelete" runat="server" Text="Delete"OnClick="btnDelete_Click" CssClass="btnDelete"></asp:LinkButton><!-- 确认对话框--><div id="dialog-confirm-delete" title="删除?"样式=显示:无;"><p>您确定要永久删除所选项目吗?</p><脚本>$(document).ready(function () {//设置对话框$('#dialog-confirm-delete').dialog({自动打开:假,模态:真,纽扣: {删除所有项目":function(){$(this).dialog("close");//===>>>如何在此处调用默认操作},取消: function () { $(this).dialog("close");}}});//显示对话框$('.btnDelete').click(function () {$('#dialog-confirm-cancel').dialog('open');//返回 false 以防止默认操作(回发)返回假;});});
所以在 click 事件处理程序中,我必须阻止 LinkButton(回发)的默认操作,而是显示对话框.
我的问题是:如果用户单击对话框中的删除所有项目"按钮,我该如何调用删除链接的默认操作(回发)来执行回发?
好的,这是我的方法(可行,但可能不是最佳解决方案):
$(document).ready(function () {$('#dialog-confirm-cancel').dialog({自动打开:假,模态:真,纽扣: {删除所有项目":function(){//调用链接按钮的 href(回发),//触发确认对话框eval($(this).dialog('option', 'onOk'));$(this).dialog("close");},取消: function () { $(this).dialog("close");}}});$('.btnDelete').click(function () {$('#dialog-confirm-delete')//将 LinkButton 的 href 值传递给对话框.dialog('option', 'onOk', $(this).attr('href')).dialog('打开');//阻止默认操作,例如,跟随链接返回假;});});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>
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, 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-ui 对话框作为带有 ASP:LinkButton 的确认对话框(如何调用 postbck)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 jquery-ui 对话框作为带有 ASP:LinkButton 的
基础教程推荐
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- WPF 模态进度窗口 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
