Re: storing session vars in C# - another problem

M

MS News \(MS ILM\)

Session["strTemp"] = "hello";

string x = Session["strTemp"].ToString();

x = Page.Session["strTemp"].ToString();

x = System.Web.HttpContext.Current.Session["strTemp"].ToString();



Will said:
storing that session worked fine, but when I try to
retrieve it from inside a component I'm writing I'm having
problems.. Here is the snippet:

private string strTemp = (String)Page.Session["strSort"];

I get the follwing error when I compile:

testControl.cs(10,36): error CS0120: An object reference
is required for nonstatic field, method, or
property 'System.Web.UI.Page.Session

what am I doing wrong? Thanks

-----Original Message-----
Session["strSort"]
Remember in C# use [ ] ; not ( ) _

Session["strSort"] = "hello";
strTemp = (String)Session["strSort"]; or .ToString();

Something like that



Will said:
In vb I used to store and retrieve sessions as follows:

Session("strSort") = "hello"
strTemp = CType(Session("strSort"), String)


how would I do this same thing in C#?


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top