JQuery confirm dialog not firing ASP Button OnClick server side event upon user's confirmation
I want to show modal confirmation dialog on ASP Button (btnRejectAll) click event and once user selects 'OK' in the modal dialog, it needs to raise the OnClick server side event of button "btnRejectAll". The following code shows modal confirmation dialog on click, but once we hit OK button, it is not firing server side event. Can anyone help me with this?
Here is my code.
<script language="javascript" type="text/javascript">
$(function() {
$("#dialogReject").dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
"Reject": function() {
$(this).dialog("close");
开发者_JAVA技巧 return true;
},
Cancel: function() {
$(this).dialog("close");
return false;
}
}
});
$("#btnRejectAll").click(function(event)
{
event.preventDefault();
$("#dialogReject").dialog("open");
});
});
<asp:Button ID="btnRejectAll" runat="server" Text="Reject All" OnClick="btnRejectAll_OnClick" />
You prevent the default action on click of btnRejectAll
but you never invoke any action on the 'Reject' action. I'm not familiar with ASP.NET but from the looks of your markup, it looks like you're cancelling the call to btnRejectAll_OnClick
. If that's a JavaScript function, then you could do this:
"Reject": function() {
$(this).dialog("close");
btnRejectAll_OnClick();
return true;
},
If it's not (and I suspect it isn't) then it's probably triggering a submit of a form. So you could instead do this:
"Reject": function() {
$(this).dialog("close");
$('#form').submit();
return true;
},
I found a way to trigger the button's server side event on dialog confirmation. Here is the code.
function ConfirmReject(detailId) {
var leaveId = $("#hdnLeaveReqId").val();
$("#dialogReject").dialog({
autoOpen: true,
height: 300,
width: 350,
modal: true,
buttons: {
"Reject": function() {
$.ajax({
type: "POST",
url: "LeaveRequestForm.aspx/RejectLeave",
data: "{'LeaveReqId':'" + leaveId + "', 'detailId':'" + detailId
+ "', 'rejectReason':'" + $("#txtRejectReason").val() + "'}",
dataType: 'json',
contentType: "application/json; charset=utf-8",
success: function(msg) { location.reload(); }
});
$(this).dialog('close');
},
Cancel: function() {
$(this).dialog("close");
}
}
});
return false;
}
<asp:Button ID="btnRejectAll" runat="server" Text="Reject All"
OnClientClick="return ConfirmReject(0);" />
In CodeBehind class:
<WebMethod()> _
Public Shared Function RejectLeave(ByVal LeaveReqId As Integer, ByVal detailId As Integer, ByVal rejectReason As String) As String
'Do Something here
Return "success"
End Function
精彩评论