用户不会显示 JQuery 模式对话框确认
JQuery modal dialog confirmation doesn't appear to the user
我正在开发一个基于 ASP.NET 并用C#编码的WebForms应用程序。此应用程序执行 CRUD 操作,每次用户想要执行操作时,我都需要向客户端显示确认消息。我决定创建一个 jQuery 函数,该函数接收窗口的标题、要向用户显示的消息以及表示操作的按钮。
这是我的Javascript函数:
var _confirm = false;
function Confirm(str, strtitle,button) {
e.preventDefault();
if (!strtitle) strtitle = 'Mensaje de error';
$('#dialog').show();
$('#dialog').html(str);
$("#dialog").dialog({
autoOpen: true,
draggable: false,
resizable: false,
modal: true,
title: strtitle,
width: 350,
height: 180,
show: "slide",
hide: "puff",
buttons: {
"No": function () {
jQuery(this).dialog("close");
},
"Yes": function () {
jQuery(this).dialog("close");
_confirm = true;
button.click();
}
},
close: function () {
jQuery(this).remove();
}
});
return false;
}
这是 ASP 按钮:
<asp:button id="btnOk" onclick="btnDGV_Click"
onclientclick="Confirm('Desea eliminar el registro', 'Confirmacion', this);"
runat="server" text="Eliminar Registro">
</asp:button>
服务器端点击的事件代码(暂时只是确认消息):
protected void btnDGV_Click(object sender, EventArgs e) {
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Registro eliminado exitosamente !!!')", true);
}
问题是当我单击该按钮时,服务器端消息始终出现,并且永远不会显示jQuery对话框。可能是什么问题?
修改你的代码:
onclientclick="Confirm('Desea eliminar el registro', 'Confirmacion', this);return;"
这会阻止按钮进行回发
并修改:
"Yes": function () {
jQuery(this).dialog("close");
__doPostBack('<%=btnOk.ClientID%>', '')
button.click();
}
如果单击"是",则此代码将进行回发和调用在按钮的 OnClick 属性上指定的方法
这里有一些事情需要检查,应该会让你明白:
- 检查客户端上的 asp:Button 呈现方式(用于您的启发)
- 检查您的客户端单击是否会阻止该元素发布到服务器。您可能希望在此处返回确认函数的结果。
- 检查确认函数的顺序。您正在尝试在初始化之前显示对话框。
相关文章:
- 打开相对于鼠标位置的CSS3/HTML5模式对话框
- Bootstrap在页面加载缓慢时会立即显示隐藏的模式对话框
- jQuery UI模式对话框覆盖淡出
- 使用Plaid Link显示自定义用户名和密码模式对话框
- 弹出格式化的模式对话框,并在用户确认时转发
- NProgress带有模式对话框以防止点击
- 使用ember模式对话框的ember中的可路由模式
- 如何在 ember.js 中的模式对话框中打开路由
- 将值从模式对话框传递给父级
- 关闭模式对话框而不刷新父级
- 如何在 javascript 中检测引导模式对话框的关闭
- 将参数传递到模式对话框
- 确认删除的模式对话框
- 当我打开模式对话框时,可以看到2个滚动条
- 用于登录/注册Angular应用程序的模式/对话框
- 选中的单选按钮在jQuery模式对话框中不能正常工作
- Safari限制?使用多种方法来显示多个自定义模式对话框
- 如何将事件绑定到模式对话框上的组件
- 单击按钮打开窗口作为使用javascript的模式对话框
- 用JavaScript制作一个按钮的动画,从按钮到屏幕中心弹出一个模式对话框