I don't believe it's loosing the Session variables. The problem is your local variables such as UID are not persisetent. Every time you create a postback to any part of the page (not necessarily clicking on a button in the user control) your UID variable
is reset. The simples thing to do is simply make UID a property so that every time you access it, it returns the session variable.
If you were truly loosing the session variables then you would be getting errors every time you tried to access Session["uid"] because if it was lost, the value would be null and any use of it would have thrown an object reference not found
error.
Don't forget to mark useful responses as Answer if they helped you towards a solution.
Marked as answer by Dino He - MSFT on Mar 22, 2012 09:45 AM
markfitzme
Star
14409 Points
2225 Posts
Re: User control unable to load session variable
Mar 17, 2012 03:13 PM|LINK
I don't believe it's loosing the Session variables. The problem is your local variables such as UID are not persisetent. Every time you create a postback to any part of the page (not necessarily clicking on a button in the user control) your UID variable is reset. The simples thing to do is simply make UID a property so that every time you access it, it returns the session variable.
protected string UID
{
get {
if(Session["uid"] != null)
return Session["uid"].ToString();
else
return string.Empty;
}
If you were truly loosing the session variables then you would be getting errors every time you tried to access Session["uid"] because if it was lost, the value would be null and any use of it would have thrown an object reference not found error.