title: What is the best way to get my control's value in OnInit()?
body: <p>I recently read <a href="http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/Truly-Understanding-Viewstate.aspx" rel="nofollow noreferrer">this article on smart use of ViewState</a> and am particularly interested in not having unnecessary static data in ViewState.  However, I'm also curious if I can do the same thing for a parent-child dropdown, like the classic Country/CountrySubDivision example.</p>
  
  <p>So I have this markup:</p>
  
  <pre><code>    &lt;asp:DropDownList runat="server" ID="ddlCountry" DataTextField="Name" DataValueField="ID" EnableViewState="false" /&gt;
      &lt;asp:DropDownList runat="server" ID="ddlCountrySubdivision" DataTextField="Name" DataValueField="ID" EnableViewState="false" /&gt;
      &lt;asp:Button runat="server" ID="btnTest" /&gt;
  </code></pre>
  
  <p>And this codebehind:</p>
  
  <pre><code>    public class Country
      {
          public string Name { get; set;}
          public int Id { get; set; }
      }
  
      public class CountrySubdivision
      {
          public string Name { get; set; }
          public int Id { get; set; }
          public int CountryId { get; set; }
      }
  
      protected override void OnInit(EventArgs e)
      {
          var l = new List&lt;Country&gt;();
          l.Add(new Country { Name = "A", Id = 1 });
          l.Add(new Country { Name = "B", Id = 2 });
          l.Add(new Country { Name = "C", Id = 3 });
          ddlCountry.DataSource = l;
          ddlCountry.DataBind();
  
          var l2 = new List&lt;CountrySubdivision&gt;();
          l2.Add(new CountrySubdivision { Name = "A1", Id = 1, CountryId = 1 }); 
          l2.Add(new CountrySubdivision { Name = "A2", Id = 2, CountryId = 1 });
          l2.Add(new CountrySubdivision { Name = "B1", Id = 4, CountryId = 2 });
          l2.Add(new CountrySubdivision { Name = "B2", Id = 5, CountryId = 2 });
          l2.Add(new CountrySubdivision { Name = "C1", Id = 7, CountryId = 3 });
          l2.Add(new CountrySubdivision { Name = "C2", Id = 8, CountryId = 3 });
  
          // this does not work: always comes out 1 regardless of what's actually selected
          var selectedCountryId = string.IsNullOrEmpty(ddlCountry.SelectedValue) ? 1 : Int32.Parse(ddlCountry.SelectedValue);
  
          // this does work: 
          var selectedCountryIdFromFormValues = Request.Form["ddlCountry"];
  
          ddlCountrySubdivision.DataSource = l2.Where(x =&gt; x.CountryId == selectedCountryId).ToList();
          ddlCountrySubdivision.DataBind();
  
          base.OnInit(e);
      }
  </code></pre>
  
  <p>So the first thing I noticed is that even when <code>EnableViewstate</code> is <code>false</code>, my country control's value is persisted across requests with no extra effort.  Sweet.  That's a lot of serialized stuff I don't need to send across the wire on form submissions.</p>
  
  <p>Then I came to the example above with a pair of parent-child drop downs, and I see that <code>ddlCountry.SelectedValue</code> is defaulting whereas <code>Request.Form["ddlCountry"]</code> is reflecting the control's value.</p>
  
  <p>Is there a way to keep <code>EnableViewState = "false"</code> without resorting to <code>Request.Form</code> to get a dependent control's value?</p>