c#
  • jquery
  • asp.net
  • arguments
  • 2012-02-26 54 views 0 likes 
    0

    我使用「eval」從數據庫獲取數據並將其放入我的應用程序(添加和刪除聯繫人)。當刪除聯繫人時,確認框顯示工作正常。data(with eval)as jquery-method的參數

    但是,我想要的是使用數據(從eval)作爲js函數的參數,以便我可以在確認框中顯示聯繫人名稱。

    下面是代碼,這是行不通的。我可以寫什麼來使它工作?

    在此先感謝。

    <asp:Label ID="FirstNameLabel" runat="server" Text='<%# Eval("FirstName") %>' /> 
    <asp:Label ID="LastNameLabel" runat="server" Text='<%# Eval("LastName") %>' /> 
    <asp:Button ID="EditLinkButton" runat="server" CommandName="Edit" Text="Edit" CausesValidation="False" /> 
    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" CausesValidation="False" OnClientClick="return confirmOnDelete(<%# Eval("FirstName") %>, <%# Eval("LastName") %>);" /> 
    

    從JS文件:

    confirmOnDelete: function (firstName, lastName) { 
         if (confirm("Are you sure that you want to delete " + firstName + " " + lastName + " ?") == true) { 
          alert("tog bort"); 
         } 
         else { 
          return false; 
         } 
        } 
    
    +1

    我相信你只需引用你的論點。 'confirmOnDelete('...','...')' – Interrobang 2012-02-26 23:35:02

    回答

    1

    處理。

    <asp:Label ID="FirstNameLabel" runat="server" Text='<%# Eval("FirstName") %>' /> 
    <asp:Label ID="LastNameLabel" runat="server" Text='<%# Eval("LastName") %>' /> 
    <asp:Button ID="EditLinkButton" runat="server" CommandName="Edit" Text="Edit" CausesValidation="False" /> 
    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" CausesValidation="False" OnClientClick="return confirmOnDelete();" /> 
    

    然後爲你的腳本

    <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script> 
    <script type="text/javascript"> 
        function confirmOnDelete() { 
         var firstName = $("[id*=FirstNameLabel]").text(); 
         var lastName = $("[id*=LastNameLabel]").text(); 
         var decision = confirm("Are you sure that you want to delete " + firstName + " " + lastName + " ?") 
         return (decision) 
        } 
    </script> 
    

    如果這是一個嵌套的過程的一部分,讓我知道,因爲它不會工作(即兩個標籤是一箇中繼器或裏面的東西)。那麼我們需要調整一下。

    0

    您可以使用jQuery的捕捉到了這個按鈕,動態地從jQuery的水平創建消息

    <script type="text/javascript"> 
        var updateButtons = $('#<%= theGridViewID.ClientID %> :button[value=Delete]'); 
        updateButtons.each(function() { 
         var onclick = $(this).attr('onclick'); 
         $(this).attr('onclick', null).click(function() { 
          // find the previus two divs and get the name of the user 
          // then create the question  
          var doPostBack = confirm("Delete this user? This action cannot be undone..."); 
          if (doPostBack) 
           return onclick(); 
          else 
           return false 
         }); 
        }); 
    </script> 
    
    +0

    我試過了,但我得到以下錯誤信息:「服務器標記不正確。」 – holyredbeard 2012-02-26 23:45:03

    +0

    @JasonCraig我有更新的問題,我只留給你找到用戶名 - 前兩個div。 – Aristos 2012-02-27 00:39:26

    相關問題