[英]Always return true when click on button when use jquery dialog
I am using jquery dialog box. 我正在使用jquery对话框。 When I click on Button popup is open but it return true and excute server side event of button.
当我单击按钮时,弹出窗口是打开的,但返回true并执行按钮的服务器端事件。
I want when user clicks on yes then return true and else return 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");
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" />
You cannot return
from a dialog. 您无法从对话框
return
。
You have to use a callback function. 您必须使用回调函数。
$("#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
}
}
});
Update your btnCancelClick
method to always return false. 更新您的
btnCancelClick
方法以始终返回false。 Then in the dialog button handlers, instead of return true or false do your postback right there. 然后在对话框按钮处理程序中,直接在此处执行回发,而不是返回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;
}
This line: 这行:
<%=ClientScript.GetPostBackEventReference(btnCancel, "")%>
will register the javascript postback call into your btnCancelClick
method. 会将javascript回发调用注册到您的
btnCancelClick
方法中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.