我正在使用jquery对话框。当我点击按钮弹出窗口打开但它返回true并执行按钮的服务器端事件。
我希望当用户点击yes然后返回true,否则返回false。
function btnCancelClick()
{
$("#dialog:ui-dialog").dialog("destroy");
$("#dialog-confirm").dialog({
resizable: false,
height: 140,
width: 400,
modal: true,
buttons: {
"Yes": function ()
{
$(this).dialog("close");
return true;
},
No: function ()
{
$(this).dialog("close");
return false;
}
}
});
}
<asp:Button ID="btnCancel" runat="server" Text="Cancel Appointment" CssClass="cssbutton"
OnClientClick="return btnCancelClick();" OnClick="btnCancel_Click" />
答案 0 :(得分:2)
您无法 return
来自对话框。
您必须使用回调函数。
$("#dialog-confirm").dialog({
resizable: false,
height: 140,
width: 400,
modal: true,
buttons: {
Yes: function() {
$(this).dialog("close");
clickedYes(); //YES CALLBACK
},
No: function() {
$(this).dialog("close");
clickedNo(); //NO CALLBACK
}
}
});
答案 1 :(得分:1)
更新btnCancelClick
方法以始终返回false。然后在对话框按钮处理程序中,而不是返回true或false,在那里做回发。
function btnCancelClick() {
$("#dialog:ui-dialog").dialog("destroy");
$("#dialog-confirm").dialog({
resizable: false,
height: 140,
width: 400,
modal: true,
buttons: {
"Yes": function () {
$(this).dialog("close");
<%=ClientScript.GetPostBackEventReference(btnCancel, "")%>;
},
No: function () {
$(this).dialog("close");
}
}
});
return false;
}
这一行:
<%=ClientScript.GetPostBackEventReference(btnCancel, "")%>
会将javascript回发通话注册到您的btnCancelClick
方法。