title: Adding PostBackTriggers and AsyncPostBackTriggers to UpdatePanel for dynamically-generated grandchild controls
body: <p>I have a page with a ScriptManager, a generic HTML drop-down list (<code>&lt;select&gt;</code>), and an UpdatePanel.  The UpdatePanel contains a PlaceHolder (for now).  During Page_Load, a number of user controls are added to the PlaceHolder (really, it's several instances of the same user control).  The number to add is not known until the page loads, so they do need to be loaded dynamically.  The drop-down list is populated with the same number of menu items, and there is javascript on the page also (using jQuery) to show only one of the controls at a time depending on the state of the drop-down list.</p>
  
  <p>Each user control has two buttons that should generate an asynchronous postback, a drop-down list that should generate an asynchronous postback on a change in selected value, and a button that should generate a synchronous postback.  If I was not generating the controls dynamically, and if there was only one control, the structure would be something like:</p>
  
  <pre><code>&lt;asp:UpdatePanel ID="myUpdatePanel" runat="server" UpdateMode="Conditional"
                   ChildrenAsTriggers="false"&gt;
      &lt;ContentTemplate&gt;
          &lt;asp:TextBox ID="textBox1" runat="server" /&gt;
          &lt;asp:TextBox ID="textBox2" runat="server" /&gt;
          &lt;asp:Button ID="asyncButton1" runat="server" Text="Button1"
                      onclick="asyncButton1_Click" /&gt;
          &lt;asp:DropDownList ID="asyncDropDown" ruant="server" AutoPostBack="true"
                      OnSelectedIndexChanged="asyncDropDown_SelectedIndexChanged" /&gt;
          &lt;asp:Button ID="asyncButton2" runat="server" Text="Button2"
                      OnClick="asyncButton2_Click" /&gt;
          &lt;asp:Button ID="syncButton" runat="server" Text="SyncButton"
                      OnClick="syncButton_Click" /&gt;
      &lt;/ContentTemplate&gt;
      &lt;Triggers&gt;
          &lt;asp:AsyncPostBackTrigger ControlID="asyncButton1" EventName="Click" /&gt;
          &lt;asp:AsyncPostBackTrigger ControlID="asyncButton2" EventName="Click" /&gt;
          &lt;asp:AsyncPostBackTrigger ControlID="asyncDropDown"
              EventName="SelectedIndexChanged" /&gt;
          &lt;asp:PostBackTrigger ControlID="syncButton" /&gt;
      &lt;/Triggers&gt;
  &lt;/asp:UpdatePanel&gt;
  </code></pre>
  
  <p>Of course, all the controls inside the ContentTemplate would actually be part of each user control.</p>
  
  <p>Adding the triggers on the server side does not seem to work because no ControlID seems to help the UpdatePanel find the relevant controls.  I can use either the control's ID or the control's UniqueID, and it does not work, and I get an error along the lines of</p>
  
  <pre><code>A control with ID 'ctl00$ContentPlaceHolder1$ctl01$asyncButton1' could not be
  found for the trigger in UpdatePanel 'myUpdatePanel'.
  </code></pre>
  
  <p>So, I wonder if I need to register the triggers in the client instead using ASP.NET Ajax.  I found <a href="http://vincexu.blogspot.com/2009/06/dynamically-register-updatepanel.html">this page</a> that basically explains how.  However, I do not know how to get the EventName taken into consideration.  The examples I have seen so far have merely been adding button clicks, but I don't know how to handle the SelectedIndexChanged event from the DropDownList.</p>
  
  <p>Any help here?  Are there examples out there I have missed?  It doesn't help, of course, that the method in the link I gave appears to be "unofficial," so I don't see any MSDN documents on the subject.</p>
  
  <p>Thanks!</p>