2012-02-26 7 views
0

"eval"を使用してデータベースからデータを取得し、アプリケーションに追加します(連絡先の追加と削除)。連絡先を削除すると、うまく動作する確認ボックスが表示されます。jquery-methodへの引数としてのデータ(評価付き)

しかし、私が望むのは、js関数の引数としてデータ(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") %>);" /> 

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

答えて

1

ハンドルにメッセージを作成することができます。スクリプト

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

これは、ネストされたプロセスの一部である場合について次に

<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();" /> 

は、それが動作しませんので、私は(すなわち、2つのラベルがリピータか何かの内側にある)を知ってみましょう。それから少し調整する必要があります。

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

+0

@ JasonCraig私は質問を更新しましたが、私はあなたのユーザー名を見つけるために残しました - 前の2つのdiv。 – Aristos

関連する問題