title: Event handler doesn't change text in Label
body: <p>Problem: the event handler <code>quantity_TextChanged</code> does not change the session variable "list" to reflect the current state. The event handler is attached to all the textboxes generated by <code>addItemRowToTable</code>, and they're told apart by their assigned ids.</p>
  
  <p>I'm definitely sure that something's missing, but I'm not sure.</p>
  
  <p>Additional Info: I need this in a way that the changes made to multiple Textboxes are all saved into 1 Session variable for later use further in the session, in the order as they are presented in the table. The values from each of the Textboxes are then used in their Label that's beside it (1 Label per Textbox).</p>
  
  <p>Desired result:</p>
  
  <pre><code>Header                      Header2 
  [TextBox with value of 42]  [Label displaying 42]
  [TextBox with value of 76]  [Label displaying 76]
  [TextBox with value of 105] [Label displaying 105]
  </code></pre>
  
  <p>WebForm1.aspx.cs</p>
  
  <pre><code>protected void Page_LoadComplete(object sender, EventArgs e)
  {
      if (Session["list"] != null)
      {
          List&lt;int&gt; numbers = Session["list"] as List&lt;int&gt;;
          int index = 0;
          foreach (int item in numbers)
          {
              tblItems.Rows.AddAt(index + 1, addItemRowToTable(item, index));
              // For debugging purposes
              Response.Write("&lt;script&gt;console.log(\"" + item.ToString() + "\");&lt;/script&gt;");
              index++;
          }
      }
  
  }
  
  private TableRow addItemRowToTable(int item, int index)
  {
      TableCell[] cells = { new TableCell(), new TableCell() };
      TableRow row = new TableRow();
  
      TextBox box = new TextBox();
      box.ID = String.Format("{0}_q", index);
      box.Attributes["type"] = "number";
      box.Attributes["min"] = "1";
      box.Attributes["width"] = "60px";
      box.TextChanged += new EventHandler(quantity_TextChanged);
      box.AutoPostBack = true;
      cells[0].Controls.Add(box);
  
      Label lbl = new Label();
      lbl.ID = String.Format("{0}_l", index);
      lbl.Text = item.ToString();
      cells[1].Controls.Add(lbl);
  
      foreach (TableCell cell in cells)
          row.Cells.Add(cell);
      return row;
  }
  
  protected void Button1_Click(object sender, EventArgs e)
  {
      if (Session["list"] != null)
      {
          List&lt;int&gt; numbers = Session["list"] as List&lt;int&gt;;
          numbers.Add(0);
          Session["list"] = numbers;
      }
      else
      {
          List&lt;int&gt; numbers = new List&lt;int&gt;();
          numbers.Add(0);
          Session["list"] = numbers;
      }
  }
  
  private void quantity_TextChanged(object sender, EventArgs e)
  {
      if (Session["list"] != null)
      {
          TextBox item = sender as TextBox;
          int position = Convert.ToInt32(item.ID.Split('_')[0]);
  
          List&lt;int&gt; numbers = Session["list"] as List&lt;int&gt;;
          numbers[position] = Convert.ToInt32(item.Text);
          Session["list"] = numbers;
      }
  }
  </code></pre>
  
  <p>WebForm1.aspx</p>
  
  <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Assignment2.WebForm1" %&gt;
  
  &lt;!DOCTYPE html&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
          &lt;div&gt;
          &lt;asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /&gt;
          &lt;br /&gt;
          &lt;br /&gt;
          &lt;asp:Table ID="tblItems" runat="server"&gt;
              &lt;asp:TableHeaderRow&gt;
                  &lt;asp:TableHeaderCell&gt;Header&lt;/asp:TableHeaderCell&gt;
                  &lt;asp:TableHeaderCell&gt;Header2&lt;/asp:TableHeaderCell&gt;
              &lt;/asp:TableHeaderRow&gt;
          &lt;/asp:Table&gt;
          &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>