title: ASP.Net dynamically add buttons and events to AJAX Accordion Pane
body: <p>I've been searching for a while on this but cant seem to get a decent answer. I am using an Accordion and dynmically adding Panes with grids on. I would also like to add a textbox and a button when each panel is added to the accordion.</p>
  
  <pre><code>//add a comments box and a submit button to the container
              Button btnComments = new Button();
              btnComments.ID = CheckName + "btnComment" + i;
              btnComments.CommandName = "SubmitComment";
              TextBox txtComments = new TextBox();
              txtComments.ID = CheckName + "txtComment" + i;
              pane.ContentContainer.Controls.Add(new LiteralControl("&lt;br /&gt;"));
              pane.ContentContainer.Controls.Add(txtComments);
              pane.ContentContainer.Controls.Add(new LiteralControl("&lt;br /&gt;"));
              pane.ContentContainer.Controls.Add(btnComments);
  </code></pre>
  
  <p>The textbox and buttons appear in the accordion as expected but the event doesn't fire. I've been reading that the event needs to be added at Page_Load but the buttons dont exist at this point.</p>
  
  <p>I tried adding CommandEvent to the accordion then I could capture the sender but again this isnt firing</p>
  
  <pre><code>&lt;asp:UpdatePanel ID="UpdatePanel1" runat="server"&gt;
      &lt;ContentTemplate&gt;
          &lt;asp:Panel ID="Panel1" runat="server" /&gt;
          &lt;asp:Accordion ID="Accordion1" runat="server" AutoSize="None" 
              RequireOpenedPane="False" SelectedIndex="-1" FadeTransitions="false"  OnItemCommand="Linked_ItemCommand"&gt;
          &lt;/asp:Accordion&gt;
          &lt;br /&gt;
          &lt;p&gt;
              &lt;asp:Button ID="btnRunChecks" runat="server" OnClick="RunChecks" Text="Run Checks" /&gt;
              &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
              &lt;asp:CheckBox ID="chkDebug" runat="server" EnableTheming="False" Text="Run in Debug mode" /&gt;
          &lt;/p&gt;
      &lt;/ContentTemplate&gt;
  &lt;/asp:UpdatePanel&gt;
  </code></pre>
  
  <p>Any ideas what I'm doing wrong - any pointers much appreciated. When clicking the button it just causes a postback and refresh losing the dynamically created accordion panes.</p>