title: Asp.NET Server Control Postback
body: <p>I have a Control I want to create.  Here's a simple example of what I was to accomplish.</p>
  
  <p>I want the control to contain a button.</p>
  
  <pre><code>Button b = new Button();
  b.Text = "Test";
  b.Click += new EventHandler(b_Click);
  
  this.Controls.Add(b);
  </code></pre>
  
  <p>Now, the control renders fine, the button shows up on the page.  The heart of the problem I'm having is that the b_Click Event Handler is never triggered.</p>
  
  <pre><code>protected void b_Click(object sender, EventArgs e)
  {
      throw new NotImplementedException();
  }
  </code></pre>
  
  <p>Any help here would be much appreciated.  I don't want to use a User Control here for purely selfish reasons and would like to totally encapsulate this in a single DLL.</p>
  
  <p>Thanks In Advance.</p>
  
  <p>EDIT**</p>
  
  <pre><code>namespace ClassLibrary1
  {
      [DefaultProperty("Text")]
      [ToolboxData("&lt;{0}:WebCustomControl1 runat=server&gt;&lt;/{0}:WebCustomControl1&gt;")]
      public class WebCustomControl1 : WebControl
      {
  
          protected override void CreateChildControls()
          {
              Button b = new Button();
                      b.ID = "button";
              b.Text = "Click Me";
              b.Click += new EventHandler(b_Click);
  
              this.Controls.Add(b);
  
              base.CreateChildControls();
          }
  
          protected void b_Click(object sender, EventArgs e)
          {
              this.Controls.Add(new LiteralControl("&lt;p&gt;Click!&lt;/p&gt;"));
          }
  
      }
  }
  </code></pre>
  
  <p>So from the comments I've tried this.  The simplest of exampes, still no go.  Is there something I'm fundamentally missing?</p>