During my current project I came across this small hiccup, where I wanted to pass value of a variable from one page to the other in a sharepoint webpart, since Webpart doesn’t provide this out of the box. I have discovered this little gem from my research.
I wanted to retain value of logged in user’s style preference for the page, the following line of code besically retains the value in the combination of page session and and class variable.
strUser = loggedInUser [strUser declared at class level]
Page.Session.Add("userStyle", strUser); //when user first time login/load on the page.
Then use this Page.Session object to retrive the value of strUser for other functions like:
strUser = Page.Session["userStyle"].ToString();
and write the value of the strUser using
Page.Response.Write("StrUser:" + strUser);
Hope this helps.