title: Is this a bug in asp:DropDownList behavior
body: <p>Below is a repro for a bug that I came across while reviewing some code.</p>
  
  <p>aspx page:</p>
  
  <pre><code>&lt;asp:DropDownList ID="ddlMain" runat="server" Visible="False" /&gt;
  &lt;asp:Button ID="btnSelect" runat="server" Text="Select" /&gt;
  </code></pre>
  
  <p>Code behind file:</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {                
              ddlMain.SelectedIndex = 0;
  }
  </code></pre>
  
  <p>Note that ddlMain has <code>visible=False</code>. On page load if I assign selectedIndex = 0; the selectedIndex value doesn't change and remain -1.</p>
  
  <p>the button is there to enable postback; on postback the above statement fails and the following exception is raised:</p>
  
  <p>'ddlMain' has a SelectedIndex which is invalid because it does not exist in the list of items.
  Parameter name: value</p>
  
  <p><strong>Why didn't the exception get raised the first time around? 
  And why does it get raised after postback?</strong></p>
  
  <p>I noticed that even though the rendersize for the dropdown is 0; there are still 12 bytes assigned in viewstate - though i couldn't verify what exactly was stored for the control. If i disable viewstate then the exception doesn't get raised after postback.</p>