title: ListBox selections does not show up after autopostback
body: <p>I know that this is not the first time a question about this issue has been posted here, but I haven't managed to find an answer to my question. </p>
  
  <p>I have a number of ListBoxes on my page:</p>
  
  <pre><code>&lt;tr&gt;
      &lt;td class="loqhArea2Area"&gt;
          &lt;asp:ListBox ID="ListBox1Val1" class="InputItem" runat="server" AutoPostBack="true"&gt;&lt;/asp:ListBox&gt;
      &lt;/td&gt;
      &lt;td class="loqhArea3Area"&gt;
          &lt;asp:ListBox ID="ListBox2Val1" class="InputItem" runat="server" AutoPostBack="true"&gt;&lt;/asp:ListBox&gt;
      &lt;/td&gt;
      &lt;td class="loqhArea4Area"&gt;
          &lt;asp:ListBox ID="ListBox3Val1" class="InputItem" runat="server"&gt;&lt;/asp:ListBox&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>These boxes are linked together in a sense, the choice in the first box is used to populate the second one and so fourth. In order to get the information from them I use this code snippet:</p>
  
  <pre><code>protected override void OnInit(EventArgs e)
  {
  // Do some other stuff ...
  
      if (!IsPostBack)
      {
          // Fill the boxes on initial load
      }
      else
      {
          // INeedTheData takes an ID-string (in this case "Val1")
          // and the selected indexes as ints
          INeedTheData("Val1",
                        ListBox1Val1.SelectedIndex,
                        ListBox2Val1.SelectedIndex,
                        ListBox3Val1.SelectedIndex);
  
      }
      // Some error handling    
  }
  </code></pre>
  
  <p>The problem is that the SelectedIndexes all returns <code>-1</code>, which obviously is not what I need. </p>
  
  <p>I have been googleing like crazy for a solution to this problem. All clues or leads are welcome. Thanks in advance!</p>
  
  <p><strong>Update:</strong>
  Maybe this can be of any clue to anyone, my predecessor (who I have not been able to reach unfortunately) implemented this rather strange code that actually works. Or should I say sort of works. The thing is we wanted some kind of more reliable code so I set out to re-write it.</p>
  
  <pre><code>INeedTheData("Val1"
      , Request.Form.AllKeys.Contains("ctl01$ListBox1Val1") ? Request.Form["ctl01$ListBox1Val1"] == string.Empty ? 0 : int.Parse(Request.Form["ctl01$ListBox1Val1"]) : 0
      , Request.Form.AllKeys.Contains("ctl01$ListBox2Val1") ? Request.Form["ctl01$ListBox2Val1"] == string.Empty ? 0 : int.Parse(Request.Form["ctl01$ListBox2Val1"]) : 0
      , Request.Form.AllKeys.Contains("ctl01$ListBox3Val1") ? Request.Form["ctl01$ListBox3Val1"] == string.Empty ? 0 : int.Parse(Request.Form["ctl01$ListBox3Val1"]) : 0);
  </code></pre>
  
  <p>This solution is not desirable since it gets the data using hardcoded html id's, which may be subject to change when rebuilding and reorganizing stuff on the page in the future. Anyhow I thought it should be entered here since it is the reason for me to rewrite it. </p>
  
  <p>As stated above, all comments are welcome! Thanks!</p>
  
  <p><strong>Update ii (answer to @Deeptechtons): Desired behaviour</strong>
  I have a group of three ListBoxes used to navigate and make choices from a tree graph. The first box (<code>ListBox1Val1</code>) is populated directly from a database. The second (<code>ListBox2Val1</code>) is empty until the user has selected his choice in the first. Doing so causes the children of the selected node in the first listbox to load into the second. Same thing goes for listbox number three (<code>ListBox3Val1</code>). Select a node in the second box and the third one is populated. </p>