Issue when Trying to Fire a ASP.NET Custom Control Button Event
<p>I have a simple asp.net test custom control that I have created and am trying to figure out why the click event will not fire. below is the code. I simply create an instance of the control on a test page with Page_Load of .aspx page that consumes the control protected void Page_Load(object sender, EventArgs e) { Page.Form.Controls.Add(new TestControl()); }</p>

<p>The page does a post back but it does not pick up the click event in the user control. Please explain what I am doing incorrectly or a better way to approach this with a specific pattern etc.</p>

<pre><code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI;

namespace WorldOfTest
{
public class TestControl : WebControl { private Button btn;
protected override void OnInit(EventArgs e)
{            
    base.OnInit(e);
}

protected override void EnsureChildControls()
{
    btn = new Button();           
    this.Controls.Add(btn); 
    base.EnsureChildControls();
}

protected override void CreateChildControls()
{

    btn.Click += new EventHandler(btn_Click);  
    btn.Text = "test button";                         
    base.CreateChildControls();
}

void btn_Click(object sender, EventArgs e)
{
    throw new NotImplementedException();
}

protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
    btn.RenderControl(writer); ;
}
</code></pre>

<p>}
}</p>
