JQuery Confirms Dialog Box Does Not Trigger ASP OnClick Button Server-Side Event When Confirming User

advertisements

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");
                    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;
          },