Reputation: 2215
I am using jquery dialog box. When I click on Button popup is open but it return true and excute server side event of button.
I want when user clicks on yes then return true and else return 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" />
Upvotes: 0
Views: 1378
Reputation: 1672
Update your btnCancelClick
method to always return false. Then in the dialog button handlers, instead of return true or false do your postback right there.
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.
Upvotes: 1
Reputation: 146310
You cannot return
from a dialog.
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
}
}
});
Upvotes: 2