title: CheckBox CheckedChanged event added from code behind
body: <p>I have a couple of checkboxes that I add from my code behind, but I can't get the CheckedChanged event to fire.</p>
  
  <p>This code is being called on page load:</p>
  
  <pre><code>CheckBox cb = new CheckBox();
  cb.AutoPostBack = true;
  cb.CheckedChanged += cb_CheckedChanged;
  
  cb.ToolTip = dr["Id"].ToString();
  cb.ID = Guid.NewGuid().ToString();
  
  Label lbl = new Label();
  lbl.Text = dr["Id"].ToString();
  lbl.AssociatedControlID = cb.ID;
  
  dvCheckboxes.Controls.Add(cb);
  dvCheckboxes.Controls.Add(lbl);
  dvCheckboxes.Controls.Add(new LiteralControl("&lt;br /&gt;"));
  </code></pre>
  
  <p>And the event:</p>
  
  <pre><code>void cb_CheckedChanged(object sender, EventArgs e)
  {
      System.Diagnostics.Debug.Write(((CheckBox)sender).ToolTip);
  }
  </code></pre>
  
  <p>I've put a breakpoint in the CheckedChanged event, but it's never reached.</p>
  
  <p><strong>What I've tried:</strong> </p>
  
  <ul>
  <li>putting the code in <code>if(!IsPostBack)</code>, but no difference.</li>
  <li><code>cb.CheckedChanged += new EventHandler(cb_CheckedChanged);</code></li>
  <li><code>cb.CheckedChanged += new EventHandler(this.cb_CheckedChanged);</code></li>
  <li><code>cb.ViewStateMode = System.Web.UI.ViewStateMode.Enabled;</code></li>
  <li>tried putting the code in <code>Page_Init</code> instead of <code>Page_Load</code></li>
  </ul>