簡體   English   中英

Asp:Button - 如果OnClientClick = True | 假

[英]Asp:Button - if OnClientClick = True | False

<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”。?

謝謝你的回復

如果你想阻止執行服務器端功能,你只需要在客戶端函數中返回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
            }
        }
    });
}

好像你試着用內置函數重新創建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

你應該嘗試使用javascript手動調用服務器端點擊事件;
簽出“ Create和“ Cancel按鈕內的代碼;

<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

 }
<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   


}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM