title: Event handler not fired for dynamically created controls
body: <p>I've got this problem with dynamically created TextBox.</p>
  
  <p>When the TextBox is created in PageLoad, it's TextChanged event was fired.<br>
  But when I dynamically delete and recreated the TextBox, the TextChanged was not fired.</p>
  
  <p>This is the code:</p>
  
  <p><strong>.aspx file</strong></p>
  
  <pre><code>&lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
      &lt;div&gt;
  
      &lt;asp:Table ID="Table1" runat="server"&gt;
        &lt;asp:TableRow&gt;
          &lt;asp:TableCell ColumnSpan="2"&gt;Fixed content&lt;/asp:TableCell&gt;
        &lt;/asp:TableRow&gt;
      &lt;/asp:Table&gt;   
      &lt;/form&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p><strong>.cs file</strong></p>
  
  <pre><code>public partial class test : System.Web.UI.Page
  {
    string myText = "a";
  
    protected void Page_Load(object sender, EventArgs e)
    {
      WriteRows();
    }
  
    private void WriteRows()
    {
      TableRow tr = new TableRow();
  
      TableCell tc = new TableCell();
      TextBox txt = new TextBox();
      txt.Text = myText;
      txt.TextChanged += new EventHandler(txt_TextChanged); // Assign event handler
      tc.Controls.Add(txt);
      tr.Controls.Add(tc);
  
      tc = new TableCell();
      tc.Text = txt.Text;
      tr.Controls.Add(tc);
  
      Table1.Controls.AddAt(1, tr);
    }
  
    private void txt_TextChanged(object sender, EventArgs e)
    {
      myText = ((TextBox)sender).Text;
      RedrawTable(); // Delete the row (incl. the TextBox) and rewrite it
    }
  
    private void RedrawTable()
    {
      Table1.Controls.RemoveAt(1);
      WriteRows();
    }
  }
  </code></pre>
  
  <p>Does anyone have a solution so that the event is always fired?</p>