Trying to display the contents of a textbox within a dynamic table ONLY after the enter key has been pressed
<p>The problem I have when the following code executes, it will first display the original contents of the textbox, then each set of keys that I pressed up until hitting 'Enter'.  So if the textbox originally contained 'Ice Cream - Pierre's Chocolate Chip' and I click in the textbox to get focus and replace it with 'Tea', I will get 4 alert boxes, each with the following content:</p>

<ol>
<li>Ice Cream - Pierre's Chocolate Chip</li>
<li>T</li>
<li>Te</li>
<li>Tea</li>
</ol>

<p>And then if I click on a different row and do something else, I will get the original 4 alert boxes from before and then the new ones...it keeps stacking and I don't know why?</p>

<p>Here is some code from my .cs file - note the "OnKeyPress" attribute I added:</p>

<pre><code>        public TCell(String celltext,String strTextBox,String strName)
        {
            int iWidth = 0;
            int intRandom =
            iWidth = Convert.ToInt32(strTextBox);
            tblCell = new TableCell();
            TextBox txtItem = new TextBox();
            txtItem.ID = strName;
            txtItem.Text = celltext;
            txtItem.Width = iWidth;
            txtItem.BorderStyle = BorderStyle.None;
            txtItem.CssClass = "cssAdjust trans";
            txtItem.Style.Add("padding", "0px 5px 0px 5px");
            txtItem.Attributes.Add("onKeyPress","captureTable(this.value);");
            txtItem.Attributes.Add("onFocus", "javascript:this.select();");
            tblCell.Controls.Add(txtItem);
        }
</code></pre>

<p>And then here is the function where I am displaying once the enter key is pressed:</p>

<pre><code> function captureTable(strValue) 
 {
     $(document).keypress(function (e) {
         if (e.which == 13) // Enter has been pressed.
         {
             e.preventDefault();
             document.getElementById("&lt;%=HiddenField1.ClientID %&gt;").value = strValue;
             alert(strValue);
         }
     });
</code></pre>

<p>Thanks in advance for any help you can give me.  I had this working using "window.event" but that locks me into IE from what I read and I am trying to use JQuery for this.</p>

<p>(UPDATE):</p>

<p>Ok, I used the code provided by kmb385 below, but I think I'm missing something still.  I don't get any alerts appearing, so I set a breakpoint at the '$(".txtHook").keypress(function(e){' line and it doesn't reach it during key entry inside of the table text box, including the enter key.</p>

<p>Here is where the code resides within the default.apsx page:</p>

<pre><code> &lt;asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"&gt;

  &lt;script type="text/javascript"&gt;

  $(document).ready(function(){ 
    $(".txtHook").keypress(function(e){ 
         if (e.which == 13) // Enter has been pressed.
         {
             e.preventDefault();
             document.getElementById("&lt;%=HiddenField1.ClientID %&gt;").value = $(this).val(); 
             alert(strValue);
         }
     });
  });
</code></pre>

<p>My inclusion of JQuery is within the body tag of the site's master page:</p>

<pre><code>&lt;body&gt;
    &lt;form id="form1" runat="server"&gt;
        &lt;asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"&gt;
            &lt;Scripts&gt;
                &lt;asp:ScriptReference Path="~/Scripts/jquery-1.4.1.min.js" /&gt;
            &lt;/Scripts&gt;
        &lt;/asp:ScriptManager&gt;
</code></pre>

<p>(FINAL UPDATE:)</p>

<p>Turns out my inclusion of JQuery was incorrect.  I moved it to the head tag of the master page and changed the code to read:</p>

<pre><code>&lt;script type="text/javascript" src="../scripts/jquery-1.4.1.min.js"&gt;&lt;/script&gt;
</code></pre>

<p>After that, the code provided my kmb385 started to work :)</p>
