Search code examples
asp.netsessionupdatepanelsession-variables

Session variable gets destroyed/nulled after UpdatePanel refreshes


I have a button inside an Update Panel and the button added as a trigger. On the click event of the button, a session is assigned:

<Triggers>
      <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>


protected void Button1_Click(object sender, EventArgs e)
{
       Session["Groupname"] = "aaa";
       UpdatePanel2.Update();
}

However after the update panel's refresh, I'm printing the session variable outside the Update panel just to test whether it's still available. To my surprise, it's now null and does not contain the assigned value. What am I doing wrong?


Solution

  • I'm printing the session variable outside the Update panel just to test whether it's still available.

    you cant. you have to print the value inside the update panel. its how update panels work.