0
<asp:Button ID="Invoice" runat="server" Text="Create Invoice" OnClientClick="CreateInvoice_Click()" OnClick="CreateInvoice_Click1"/>



        <script type="text/javascript" language="javascript">
                   function Create_Invoice() {
                    $("#dialog-confirm").dialog({
                        resizable: false,
                        height: 180,
                        modal: true,
                        buttons: {
                            Create: function () {
                                $(this).dialog("close");
                            },
                            Cancel: function () {
                              //code needed here
                                $(this).dialog("close");
                            }
                        }
                    });
                }
                </script>



    <p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>Are you sure?</p>

因此用户按下“创建发票”按钮,弹出窗口允许用户选择“创建”或“取消”。

如果用户单击“创建”或“取消”,则“CreateInvoice_Click”函数在后面的代码上运行。我想知道的(需要进入“取消”功能')如果单击取消,我该怎么说忽略 OnClick="CreateInvoice_Click1"。?

感谢您的任何回复

4

4 回答 4

2

如果您想阻止服务器端函数执行,您只需在客户端函数中返回 false。

function Create_Invoice() {
    $("#dialog-confirm").dialog({
        resizable: false,
        height: 180,
        modal: true,
        buttons: {
            Create: function () {
                $(this).dialog("close");
            },
            Cancel: function () {
              //code needed here
                $(this).dialog("close");
                return false;// that's all what you need
            }
        }
    });
}
于 2013-05-10T14:13:10.523 回答
0

似乎您正在尝试使用内置函数重新创建 javascript 所做的事情。

function confirmation() {
    var answer = confirm("Leave tizag.com?")
    if (answer){
        alert("Bye bye!")
        window.location = "http://www.google.com/";
    }
    else{
        alert("Thanks for sticking around!")
    }
}

取自http://www.tizag.com/javascriptT/javascriptconfirm.php

于 2013-05-10T14:10:53.697 回答
0

您应该尝试使用 javascript 手动调用服务器端点击事件;
签出里面的代码CreateCancel按钮;

<script type="text/javascript">
         $('#test').on('click', function(e){
            e.preventDefault();
            $("#dialog-confirm").dialog({
              resizable: false,
              height: 180,
              modal: true,
              buttons: {
                 Create: function () {
                     $(this).dialog("close");
                     // manually calling serverside click event
                     $('#buttonHidden').click();
                 },
                  Cancel: function () {
                     //code needed here
                     $(this).dialog("close"); 
                      // don't call it manually here and thus it won't fire the serverside click event
                  }
              }
         });
      });
    </script>
    // your button here to call javascript
    <button id="test" runat="server">Create Invoice</button>
    // the hidden button just to hold the CreateInvoice_Click1 which is fired from fireClick()
    <asp:Button ID="buttonHidden" runat="server" Style="display: none" OnClick="CreateInvoice_Click1" />

你的代码在后面;

 protected void CreateInvoice_Click1(Object sender, EventArgs e)
 {
    //your server side code

 }
于 2013-05-10T14:46:36.200 回答
0
<asp:Button ID="Invoice" runat="server" Text="Create Invoice" OnClientClick="return Create_Invoice()" OnClick="CreateInvoice_Click1"/>

<script type="text/javascript" language="javascript">
function Create_Invoice() {
    $("#dialog-confirm").dialog({
        resizable: false,
        height: 180,
        modal: true,
        buttons: {
            Create: function () {
                $(this).dialog("close");
                return true;
            },
            Cancel: function () {
              //code needed here
                $(this).dialog("close");
                return false;
            }
        }
    });
}

<p id="dialog-confirm"><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>Are you sure?</p>

你的代码在后面;

protected void CreateInvoice_Click1(Object sender, EventArgs e)
{
//your server side code   


}
于 2013-05-15T05:44:44.963 回答