简体   繁体   中英

how to use call back in jquery confirm dialog

Javascript code

  function btnCancelClick()
                {
                    $("#dialog:ui-dialog").dialog("destroy");

                    $("#dialog-confirm").dialog({
                        resizable: false,
                        height: 140,
                        width: 400,
                        modal: true,
                        buttons: {
                            "Yes": function ()
                            {                       
                                $(this).dialog("close");
                                      //Yes callback
                            },
                            No: function ()
                            {                       
                                $(this).dialog("close");
                                    //No callback
                            }
                        }

                    });             
                }

Aspx code

 <div class="demo">
        <div id="dialog-confirm" title="Do you want to cancel the appointment?">
        </div>
    </div>

     <asp:Button ID="btnCancel" runat="server" Text="Cancel" CssClass="cssbutton"
                                        OnClientClick="return btnCancelClick();" OnClick="btnCancel_Server_Click" />
<asp:UpdatePanel ID="updatePanelTable" runat="server">
                        <ContentTemplate>
.
.
.

</ContentTemplate>
<Triggers>
                            <asp:AsyncPostBackTrigger ControlID="btnCancel" EventName="Click" />
                        </Triggers>
                    </asp:UpdatePanel>

Server side code:

protected void btnCancel_Server_Click(object sender, EventArgs e)
    {
        //Server side code.
    }

I use jquery dialog for showing confirm box. when click on button it always fire server side event of button.I have to fire server side event on click of Yes if i click on No then return false. I searched on google they told me use callback for that i dont know how to use call back in this kind of stuff.

Since you can have a callback whenever the user answered "Yes" or "No", you could have something like this :

function btnCancelClick()
{
    $("#dialog:ui-dialog").dialog("destroy");
    $("#dialog-confirm").dialog({
        resizable: false,
        height: 140,
        width: 400,
        modal: true,
        buttons: {
           "Yes": function ()
           {                       
               $(this).dialog("close");
               //Yes callback
               callback();
           },
           No: function ()
           {                       
               $(this).dialog("close");
               //No callback
               callback();
           }
       }
   });

   function callback() {
       // whatever needs to be done once the user choose Yes or No
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM