title: Event on dynamically created checkbox asp.net
body: <p>I started to programming with asp.net, I have a table with some checkboxes.</p>
  
  <p>The problem is, I can't create static tables, because this action is linked with some parameters. Anyway.. When I click on the First checkbox I want to invert the other checkboxes in this table.
  How can I catch this event?</p>
  
  <pre><code>&lt;%@ Page Title="Fragebogen generieren" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Generate.aspx.cs" Inherits="MAXXREC.Generate" SmartNavigation="True" %&gt;
  
  &lt;asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server"&gt;
      &lt;h2&gt;&lt;%: Title %&gt;.&lt;/h2&gt;&lt;br /&gt; &lt;br /&gt;
      &lt;asp:Panel id="pCustomize" runat="server"&gt;&lt;/asp:Panel&gt; &lt;br /&gt;&lt;br /&gt;
      &lt;asp:Button id="btnSave" class="btn btn-default" Text="Save" runat="server" OnClick="btnSave_Click"&gt;&lt;/asp:Button&gt; 
  &lt;/asp:Content&gt;
  </code></pre>
  
  
  
  <pre><code>private bool SelectTheData()
          {
              dtQuestionBlock = taQuestionBlock.GetData();
              try
              {
                  int rows = dtQuestionBlock.Rows.Count;
  
                  for (int i = 0; i &lt; rows; i++)
                  {
                      UpdatePanel updatePanel = new UpdatePanel();
                      updatePanel.ID = "up" + dtQuestionBlock.Rows[i][1].ToString();
  
                      Label lbl = new Label();
                      lbl.ID = "lbl" + dtQuestionBlock.Rows[i][1].ToString();
                      lbl.CssClass = "h4";
  
                      lbl.Attributes.Add("runat", "server");
                      lbl.Text = dtQuestionBlock.Rows[i][1].ToString();
                      pCustomize.Controls.Add(lbl);
                      pCustomize.Controls.Add(new Literal() { ID = "br" + i, Text = "&lt;br /&gt;&lt;br /&gt;" });
  
                      HtmlTable tbl = new HtmlTable();
                      tbl.Width = "100%";
                      tbl.Attributes.Add("class", "table");
                      tbl.ID = "htmltbl" + dtQuestionBlock.Rows[i][1].ToString();
  
                      HtmlTableRow htr = new HtmlTableRow();
  
                      HtmlTableCell hcella = new HtmlTableCell();
                      CheckBox acb = new CheckBox();
                      acb.ID = "cb" + dtQuestionBlock.Rows[i]["name"].ToString();
                      //acb.CheckedChanged += new EventHandler(cb_CheckedChanged);
                      hcella.Width = "30px";
                      hcella.Controls.Add(acb);
                      htr.Cells.Add(hcella);
                      HtmlTableCell hcellf = new HtmlTableCell();
                      hcellf.InnerText = "Frage";
                      hcellf.Style.Add("font-weight", "bold");
                      hcellf.Style.Add("font-size", "15px");
                      htr.Cells.Add(hcellf);
  
                      tbl.Rows.Add(htr);
  
                      string cont = dtQuestionBlock.Rows[i]["ID"].ToString();
  
                      dtQuestion = taQuestion.GetDataBy1(Convert.ToInt32(cont));
  
                      nCountTables = i;
  
                      for (int j = 0; j &lt; dtQuestion.Rows.Count; j++)
                      {
                          HtmlTableRow tr = new HtmlTableRow();
  
                          HtmlTableCell cell = new HtmlTableCell();
                          acb = new CheckBox();
                          acb.ID = "cb" + dtQuestion.Rows[j]["content"].ToString();
                          cell.Width = "30px";
                          cell.Controls.Add(acb);
                          tr.Cells.Add(cell);
                          cell = new HtmlTableCell();
                          cell.InnerText = dtQuestion.Rows[j]["content"].ToString();
                          cell.ID = "cell" + j + "_" + dtQuestion.Rows[j]["content"].ToString();
                          tr.Cells.Add(cell);
  
                          tbl.Rows.Add(tr);
                      }
                      updatePanel.ContentTemplateContainer.Controls.Add(tbl);
                      //tbl.Visible = false;
                      pCustomize.Controls.Add(updatePanel);
                      pCustomize.Controls.Add(new Literal() { ID = "br" + i + rows, Text = "&lt;br /&gt;" });
                  }
                  return true;
              }
              catch (Exception ex)
              {
                  Type cstype = ex.GetType();
                  ClientScriptManager cs = Page.ClientScript;
                  String cstext = ex.ToString();
                  cs.RegisterStartupScript(cstype, "PopupScript", cstext, true);
                  return false;
              }
              finally
              {
                  taQuestionBlock.Dispose();
                  dtQuestionBlock.Dispose();
              }
          }
  </code></pre>