title: Attempting to pass selected DropDownList to Session
body: <p>I'm trying to pass the value of a dropdownlist to a session variable, and then cast this value into a text label for a review page. This value then needs to be passed to an sql table (not an issue). Where the issue lies is every time I attempt to call the value (or index, I've tried both) of the dropdownlist in a label I get a null exception.
  Here's my code for one of the dropdowns on the first page, and the attempt to bind it from the created session on the next:
  FirstPage.aspx</p>
  
  <pre><code>&lt;asp:DropDownList ID="ddlInnoc" runat="server"&gt;
  &lt;asp:ListItem Value="0"&gt;No&lt;/asp:ListItem&gt;
  &lt;asp:ListItem Value="1"&gt;Yes&lt;/asp:ListItem&gt;
  &lt;/asp:DropDownList&gt;
  </code></pre>
  
  <p>FirstPage.aspx.cs</p>
  
  <pre><code>Session["Jabs"] = ddlInnoc.SelectedIndex;
  </code></pre>
  
  <p>SecondPage.aspx</p>
  
  <pre><code>&lt;asp:Label ID="lblJabs" runat="server"&gt;&lt;/asp:Label&gt;
  </code></pre>
  
  <p>SecondPage.aspx.cs</p>
  
  <pre><code>lblJabs.Text = Session["Jabs"].ToString();
  </code></pre>
  
  <p>Please somebody tell me I'm just being stupid! 
  The exception I receive is as follows:</p>
  
  <pre><code>Object reference not set to an instance of an object.
  
  Description: An unhandled exception occurred during the execution of the current web
  request. Please review the stack trace for more information about the error and where it originated in the code. 
  
  Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
  
  Source Error: 
  
  
  Line 11:     {
  Line 12:         //Capture session values from previous page and send to relevant    labels
  Line 13:         **lblGroup.Text = Session["NoInGroup"].ToString();**
  Line 14:         lblFirstName.Text = Session["FirstName"].ToString();
  Line 15:         lblMiddleName.Text = Session["MiddleName"].ToString();
  </code></pre>
  
  <p>Whats kinda strange is that I can successful grab the SelectedIndex of a different DropDownList on a different page. Its making me tear my hair out!</p>