title: Session Variable in ASP.NET returns previous value in ModalBox?
body: <p>I have a question regarding passing Session Variables to a text-box in an Update Panel (which is displayed in a Modal PopUp). 
  This is the code I have so far:</p>
  
  <p><strong>ASPX CODE:</strong></p>
  
  <pre><code>        &lt;asp:TemplateField HeaderText="Link"&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:LinkButton ID="LinkButton1" Text="Link" runat="server" OnClick="LinkButton1_Click"  /&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
      &lt;/Columns&gt;
  &lt;/asp:gridview&gt;
  
  &lt;asp:UpdatePanel ID="UpdatePanel1" runat="server" OnLoad="panel_Load"&gt;
      &lt;ContentTemplate&gt;
          &lt;asp:Button ID="OKButton" runat="server" Text="Close" /&gt;
          &lt;asp:Label ID="Label1" runat="server" Text="Label"&gt;&lt;/asp:Label&gt;
      &lt;/ContentTemplate&gt;
  &lt;/asp:UpdatePanel&gt;
  
  &lt;asp:ModalPopupExtender ID="mpe" runat="server" TargetControlID="ClientButton" PopupControlID="UpdatePanel1" OkControlID="OKButton"&gt;
  &lt;/asp:ModalPopupExtender&gt;
  
  &lt;asp:Button ID="ClientButton" runat="server" Text="Launch Modal Popup (Client)" style="display:none;" /&gt;
  </code></pre>
  
  <p><strong>CODE BEHIND (C#):</strong></p>
  
  <pre class="lang-cs prettyprint-override"><code>protected void LinkButton1_Click(object sender, EventArgs e)
  {
      GridViewRow clickedRow = ((LinkButton)sender).NamingContainer as GridViewRow;
      Label lbl_nme = (Label)clickedRow.FindControl("lbl_name");
      String string_nme = lbl_nme.Text.ToString();
      Session["Name"] = string_nme;
      mpe.Show();
  }
  
  protected void panel_Load(object sender, EventArgs e)
  {
      Label1.Text = (string)(Session["Name"]);
  }
  </code></pre>
  
  <p>So basically I have a GridView with name, address etc… When the user clicks on a link in a row, then the value for the name field of that row is saved as a session variable. Then a Modal PopUp is displayed. The Modal PopUp should then show the Name which was saved as a Session variable.</p>
  
  <p>The code sort of works. What I’m experiencing is that when I click a row, the Label1.Text in the Modal PopUp is empty. So if I close the PopUp then click another link in another row, the PopUp then displays the Name of the row that was clicked previously.</p>
  
  <p>In other words.. If row 1 has Name “Kevin” and row 2 has Name “Nathaniel”, and I click a link to open the Modal PopUp of row 1, I would expect the PopUp to display “Kevin”. But it doesn’t. The first time I click a link after rebuilding the application, nothing is displayed. But say I click row 2 after clicking row1, then the Modal PopUp displays the value of the row I clicked before, i.e. “Kevin” when I expect it to be “Nathaniel”.</p>
  
  <p>I hope I didn’t confuse anyone. I’m a newbie and I’m just getting into this stuff, so I’d appreciate it if someone could help me out, preferably with examples of code etc.</p>
  
  <p>Thank you. Much appreciated.</p>