title: How can I programmatically add triggers to an ASP.NET UpdatePanel?
body: <p>I am trying to write a quote generator. For each product, there are a set of options. I want to dynamically add a drop down list for each option, and then have their SelectedIndexChanged events all wired up to update the quote cost. </p>
  
  <p>I am not having any trouble adding the DropDownList controls to my UpdatePanel, but I can't seem to wire up the events. </p>
  
  <p>After the page loads, the drop downs are there, with their data, but changing them does not call the SelectedIndexChanged event handler, nor does the QuoteUpdatePanel update.
  I have something like this:</p>
  
  <p><strong>Edit:</strong> Since <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.asyncpostbacktrigger.aspx" rel="nofollow noreferrer">programmatically adding AsyncPostBackTrigger controls is not supported</a>, I've change my code to this, but I still don't get the event:</p>
  
  <p><strong>Edit 2:</strong> Tried adding a PlaceHolder to add the drop down lists to (instead directly into the ContentTemplateContainer, still no events firing.</p>
  
  <p>QuotePanel.ASCX</p>
  
  <pre><code>&lt;asp:ScriptManager ID="ScriptManager" runat="server" /&gt;
  
  &lt;asp:UpdatePanel ID="QuoteUpdatePanel" runat="server" ChildrenAsTriggers="true"&gt;
      &lt;ContentTemplate&gt;
          Cost: &lt;asp:Label ID="QuoteCostLabel" runat="server" /&gt;
          &lt;fieldset id="standard-options"&gt;
              &lt;legend&gt;Standard Options&lt;/legend&gt;
              &lt;asp:UpdatePanel ID="StandardOptionsUpdatePanel" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional"&gt;
                  &lt;ContentTemplate&gt;
                  &lt;asp:PlaceHolder ID="StandardOptionsPlaceHolder" runat="server" /&gt;                   
                  &lt;/ContentTemplate&gt;
              &lt;/asp:UpdatePanel&gt;
          &lt;/fieldset&gt;
      &lt;/ContentTemplate&gt;
  &lt;/asp:UpdatePanel&gt;
  </code></pre>
  
  <p>The code to add the dropdowns and the event they are to be wire up for:</p>
  
  <pre><code>protected void PopluateUpdatePanel(IEnumerable&lt;IQuoteProperty&gt; standardOptions)
  {
      foreach (IQuoteProperty standardOp in standardOptions)
      {
          QuotePropertyDropDownList&lt;IQuoteProperty&gt; dropDownList = new QuotePropertyDropDownList&lt;IQuoteProperty&gt;(standardOp);
          dropDownList.SelectedIndexChanged += QuotePropertyDropDown_SelectedIndexChanged;
          dropDownList.ID = standardOp.GetType().Name + "DropDownList";
          dropDownList.CssClass = "quote-property-dropdownlist";
  
          Label propertyLabel = new Label() {Text = standardOp.Title, CssClass = "quote-property-label"};
  
          StandardOptionsPlaceHolder.Controls.Add(propertyLabel);
          StandardOptionsPlaceHolder.Controls.Add(dropDownList);
  
          _standardOptionsDropDownLists.Add(dropDownList);
  
          ScriptManager.RegisterAsyncPostBackControl(dropDownList);
  
      }
  
  }
  
  void QuotePropertyDropDown_SelectedIndexChanged(object sender, EventArgs e)
  {
      QuoteCostLabel.Text = QuoteCost.ToString();
      StandardOptionsUpdatePanel.Update();
  }
  </code></pre>