title: How to use Session to save value on current row of GridView, to be copied into TextBox? - VB.Net
body: <p>I'm trying to use <code>Session</code> to record the data of the 1st column of current row to be used in another Web From which will be opened using a <code>LinkButton</code> that is in the <code>GridView</code>.</p>
  <p>Basically, if I click the <code>LinkButton</code> on the 1st row, the 1st column data of the 1st row will be copied to the next Web Form. But before I do that, I want to do a smaller scale experiment to test it. So instead for now I want the <code>Session</code> to copy the data into a <code>TextBox</code> in the same form.</p>
  <p>For reference, here is the design of the <code>GridView</code>, most rows removed since they're not relevant:</p>
  <pre><code>&lt;asp:GridView ID=&quot;GridView1&quot; runat=&quot;server&quot; AutoGenerateColumns=&quot;False&quot; 
      BorderColor=&quot;Black&quot; BorderStyle=&quot;Solid&quot; BorderWidth=&quot;1px&quot; Font-Names=&quot;Arial&quot;&gt;
      &lt;AlternatingRowStyle BackColor=&quot;#B7DBFF&quot; /&gt;
      &lt;Columns&gt;
  
          &lt;asp:BoundField DataField=&quot;caseticket&quot; HeaderText=&quot;Ticket #&quot; &gt;
                  &lt;HeaderStyle BackColor=&quot;#000066&quot; ForeColor=&quot;White&quot; Wrap=&quot;False&quot; width=&quot;10%&quot;/&gt;
                  &lt;ItemStyle Wrap=&quot;False&quot; /&gt;
          &lt;/asp:BoundField&gt;
                                                                  
          &lt;asp:TemplateField ShowHeader=&quot;False&quot;&gt;
              &lt;HeaderStyle BackColor=&quot;#000066&quot; ForeColor=&quot;White&quot; Wrap=&quot;False&quot; width=&quot;10%&quot;/&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:linkbutton ID=&quot;newLog&quot; runat=&quot;server&quot; onclick = &quot;CaseLog_click&quot; &gt;Add Log &lt;/asp:linkbutton&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
  
      &lt;/Columns&gt;
      &lt;HeaderStyle BackColor=&quot;#000066&quot; /&gt;
      &lt;RowStyle HorizontalAlign=&quot;Center&quot; /&gt;
  &lt;/asp:GridView&gt;
  </code></pre>
  <p>For the <code>TemplateField</code> is a <code>LinkButton</code> with a <code>onclick</code> property. With it, I created the sub:</p>
  <pre><code>Sub CaseLog_click(ByVal sender As Object, ByVal e As EventArgs)
  
      Session(&quot;ticket&quot;) = GridView1.SelectedRow.Cells(1).Text
      'Response.Redirect(&quot;~/CaseLog.aspx&quot;)  ==&gt; will be using this to proceed to next Web Form
      TextBox1.Text = Session(&quot;ticket&quot;)    '==&gt; For test use only.
  
  End Sub
  </code></pre>
  <p>If I only kept the <code>Response.Redirect(&quot;~/CaseLog.aspx&quot;)</code> in the sub, the <code>LinkButton</code> can direct me to the next Web Form. But as it is now, during testing when I use the <code>LinkButton</code> I get an error on the <code>session</code> line of the sub.</p>
  <p><code>Object reference not set to an instance of an object.</code></p>
  <p>Is the code salvageable, or do  I need to redo this?</p>
  <p>Thanks.</p>