title: ASP .NET Button event handlers do not fire on the first click, but on the second click after a PostBack
body: <p><strong>Background:</strong> I am customizing an existing ASP .NET / C# application. It has it's own little "framework" and conventions for developers to follow when extending/customizing its functionality. I am currently extending some of it's administrative functionality, to which the framework provides a contract to enforce implementation of the <code>GetAdministrationInterface()</code> method, which returns <code>System.Web.UI.Control</code>. This method is called during the <code>Page_Load()</code> method of the page hosting the GUI interface.</p>
  
  <p><strong>Problem:</strong> I have three buttons in my GUI, each of which have been assigned an Event Handler. My administration GUI loads up perfectly fine, but clicking any of the buttons doesn't do what I expect them to do. However, when I click them a second time, the buttons work.</p>
  
  <p>I placed breakpoints at the beginning of each event handler method and stepped through my code. On the first click, none of the event handlers were triggered. On the second click, they fired.</p>
  
  <p>Any ideas?</p>
  
  <p><strong>Example of Button Definition (within <code>GetAdministrationInterface</code>)</strong></p>
  
  <pre><code>public override Control GetAdministrationInterface()
  {
      // more code...
  
      Button btn = new Button();
      btn.Text = "Click Me!";
      btn.Click += new EventHandler(Btn_Click);
  
      // more code...
  }
  </code></pre>
  
  <p><strong>Example of Event Handler Method Definition</strong></p>
  
  <pre><code>void Btn_Click(object sender, EventArgs e)
  {
      // Do Something
  }
  </code></pre>
  
  <p><strong><code>Page_Load</code> Method that calls <code>GetAdministrationInterface</code></strong></p>
  
  <pre><code>protected void Page_Load(object sender, System.EventArgs e)
  {
      if (!Page.IsAsync)
      {
          List&lt;AdministrationInterface&gt; interfaces = &lt;DATABASE CALL&gt;;
          foreach(AdministrationInteface ai in interfaces)
          {
              placeholderDiv.Controls.Add(ai.GetAdministrationInterface());
          }
      }
  }
  </code></pre>