title: ASP.NET / C#: DropDownList SelectedIndexChanged in server control not firing
body: <p>I'm creating a server control that basically binds two dropdown lists, one for country and one for state, and updates the state dropdown on the country's selectedindexchanged event. However, it's not posting back. Any ideas why? Bonus points for wrapping them in an UpdatePanel (having rendering issues; maybe because I don't have a Page to reference?)</p>
  
  <p>Here's what I  have (with some extra data access stuff stripped out):</p>
  
  <pre><code>public class StateProv : WebControl
  {
      public string SelectedCountry;
      public string SelectedState;
  
      private DropDownList ddlCountries = new DropDownList();
      private DropDownList ddlStates = new DropDownList();
  
      protected override void OnLoad(EventArgs e)
      {
          base.OnLoad(e);
  
          IList&lt;Country&gt; countries = GetCountryList();
          IList&lt;State&gt; states = new List&lt;State&gt;();
  
          if (SelectedCountry != null &amp;&amp; SelectedCountry != "")
          {
              states = GetStateList(GetCountryByShortName(SelectedCountry).CountryShortName);
          }
          else
          {
              states.Add(new State { CountryId = 0, Id = 0, StateLabelName = "No states available", StateLongName = "No states available", StateShortName = "" });
          }
  
          ddlCountries.DataSource = countries;
          ddlCountries.DataTextField = "CountryLongName";
          ddlCountries.DataValueField = "CountryShortName";
          ddlCountries.SelectedIndexChanged += new EventHandler(ddlCountry_SelectedIndexChanged);
          ddlCountries.AutoPostBack = true;
  
          ddlStates.DataSource = states;
          ddlStates.DataTextField = "StateLongName";
          ddlStates.DataTextField = "StateShortName";
  
          ddlCountries.DataBind();
          ddlStates.DataBind();
  
          if (!string.IsNullOrEmpty(SelectedCountry))
          {
              ddlCountries.SelectedValue = SelectedCountry;
  
              if (!string.IsNullOrEmpty(SelectedState))
              {
                  ddlStates.SelectedValue = SelectedState;
              }
          }            
      }
  
  
      protected override void RenderContents(HtmlTextWriter output)
      {
          ddlCountries.RenderControl(output);
          ddlStates.RenderControl(output);
      }
  
      private IList&lt;Country&gt; GetCountryList()
      {
          //return stuff
      }
  
      private IList&lt;State&gt; GetStateList(Country country)
      {
          //return stuff
      }
  
      private IList&lt;State&gt; GetStateList(string countryAbbrev)
      {
          Country country = GetCountryByShortName(countryAbbrev);
          return GetStateList(country);
      }
  
      private Country GetCountryByShortName(string countryAbbrev)
      {
          IList&lt;Country&gt; list = dataAccess.RetrieveQuery&lt;Country&gt;();
          //return stuff
      }
  
      private IList&lt;State&gt; GetAllStates()
      {
          //return stuff
      }
  
      protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
      {
          IList&lt;State&gt; states = GetStateList(GetCountryList()[((DropDownList)sender).SelectedIndex]);
          ddlStates.DataSource = states;
          ddlStates.DataBind();
      }
  }
  </code></pre>
  
  <p><strong>Edit:</strong> Viewstate is on the page, and other controls on the page perform postbacks correctly, just not this.</p>