简体   繁体   English

如何在jQuery确认对话框中使用回叫

[英]how to use call back in jquery confirm dialog

Javascript code JavaScript代码

  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 Aspx代码

 <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. 我使用jQuery对话框显示确认框。 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. 当单击按钮时,它总是触发button的服务器端事件。如果我单击“否”,则必须单击“是”来触发服务器端事件,然后返回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
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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