title: Dynamic Button not calling click event
body: <p>I have a asp Table in my page and I create its contents from the code-behind. For this particular TableRow I need to create a multiline textbox and a button, when I click a button I save the textbox content into my DB. But my click function isn't getting called. Here's my code:</p>
  
  <pre><code>ContentPlaceHolder cont = new ContentPlaceHolder();
  HtmlGenericControl br = new HtmlGenericControl();
  HtmlGenericControl br2 = new HtmlGenericControl();
  TextBox texto = new TextBox();
  Button btnSalvarTexto = new Button();
  btnSalvarTexto.ID = "btnSalvar";
  btnSalvarTexto.Click += new EventHandler(btnSalvarTexto_Click);
  btnSalvarTexto.CssClass = "botao";
  btnSalvarTexto.Text = "Salvar";
  cont.ID = "Placeholder";
  texto.ID = "TextBoxObs";
  texto.Width = 300;
  texto.TextMode = TextBoxMode.MultiLine;
  texto.Rows = 3;
  br.InnerHtml = "&lt;br&gt;&lt;br&gt;&lt;div style='width:300px;background-color:#fff;padding:15px;'&gt;";
  cont.Controls.Add(br);
  cont.Controls.Add(texto);
  cont.Controls.Add(btnSalvarTexto);
  br2.InnerHtml = "&lt;/div&gt;";
  cont.Controls.Add(br2);
  td2.Controls.Add(cont);
  tr2.Cells.Add(td2);
  TablePrecos.Rows.Add(tr2);
  </code></pre>
  
  <p>The event handler:</p>
  
  <pre><code>void btnSalvarTexto_Click(object sender, EventArgs e)
  {
      //Update command here, this function doesn't even gets called, so it doesn't matter what it does
  }
  </code></pre>
  
  <p>What's wrong with my code? I've put a breakpoint in the <code>btnSalvarTexto_Click</code> function and it never reaches it.</p>
  
  <p>EDIT: Ok, the function wich creates these controls is called CriarCapa, it's called in <code>Page_LoadComplete</code> like this:</p>
  
  <pre><code> protected void Page_LoadComplete(object sender, EventArgs e)
   if (!IsPostBack)
   {
      CriarCapa();
   }
  </code></pre>
  
  <p>So yeah, I'm testing to see if it's not a postback.</p>