title: How to add event to custom control that fired when click a button in it?
body: <p>I want to build custom control consist of html code which shows table, and in the footer of this table I need to add three buttons.
  What I did is inherit from WebControl class:  </p>
  
  <pre><code>public class MyCustomControl : WebControl {  
      protected override void RenderContents(HtmlTextWriter output)
      {  
      // using output.Write I write the table in html code  
      // and I write the three buttons using &lt;input&gt; tag in html not &lt;asp:button&gt; tag
      }  
  }
  </code></pre>
  
  <p>What I want here is to add three events one to each button I wrote, and those events would be used in the user interface and fired when the proper button clicked:  </p>
  
  <pre><code>&lt;asp:MyCustomControl runat="server" id="myCtrl" onButton1Click="Button1_Click" onButton2Click="Button2_Click" /&gt;  
  </code></pre>
  
  <p>How can I do this ?  </p>
  
  <p>Thanx</p>
  
  <p>*<strong>*UPDATE1:</strong><br>
  The render code in my custom control would be like this:  </p>
  
  <pre><code>protected override void RenderContents(HtmlTextWriter output)
      {
      output.Write("&lt;table&gt; ......");
      output.Write("&lt;input id='button1' type='button'&gt;");
      output.Write("&lt;input id='button2' type='button'&gt;");
      output.Write("&lt;input id='button3' type='button'&gt;");
      output.Write(".........&lt;/table&gt;");
      }
  </code></pre>
  
  <p>So how would I make 'button1' fire the event on server side?  </p>
  
  <p>*<strong>*UPDATE2:</strong><br>
  This is what the code looks like:  </p>
  
  <pre><code>public class MyCustomControl : WebControl
  {
  
   public Button Button1 = new Button {Text = "Button1"};
   public Button Button2 = new Button {Text = "Button2"};
  
   public event EventHandler Button1_Click;
   public event EventHandler Button2_Click;
  
   protected override void OnPreRender(EventArgs e)
   {
     Button1.Click += Button1Click;
     Button2.Click += Button2Click;
     base.OnPreRender(e);
   }
  
   protected override void RenderContents(HtmlTextWriter output)
   {
    using (var plh = new PlaceHolder())
     {
     var htmlCode = new StringBuilder();
     htmlCode.Append("....html code for table...");
  
     var container = new HtmlGenericControl { InnerHtml = htmlCode.ToString() };
  
     plh.Controls.Add(container);
     plh.Controls.Add(Button1);
     plh.Controls.Add(Button2);
     plh.RenderControl(output);
  
     htmlCode.Append("..../html code for table...");
     }
   }
  
   private void Button1Click(object sender, EventArgs e)
   {
    if (Button1_Click != null)
        Button1_Click(this, e);
   }
  
   private void Button2Click(object sender, EventArgs e)
   {
    if (Button2_Click != null)
        Button2_Click(this, e);
   }
  </code></pre>
  
  <p>And in the page.aspx:</p>
  
  <pre><code>&lt;cc1:MyCustomControl ID="myCtrl" runat="server" onbutton1_click="MyCustomControl_Button1_Click" /&gt;
  </code></pre>
  
  <p>But even with this the button1's click method 'MyCustomControl_Button1_Click' not called.</p>