Global Variables vs. ASP.NET Session State?

You should use Session state if you want to store information that is specific only to the current user For example in one page of the application you could store some value into the session: SomeType someValue = ... Session"someKey" = someValue and then later on other page retrieve it from the session: SomeType someValue = (SomeType)Session"someKey".

You should use Session state if you want to store information that is specific only to the current user. For example in one page of the application you could store some value into the session: SomeType someValue = ... Session"someKey" = someValue; and then later on other page retrieve it from the session: SomeType someValue = (SomeType)Session"someKey".

A similar question was asked and I think this answer pretty much sums up all your options.

The pattern you are looking for is quite easy. There are a couple of ways to accomplish it. Create an object and store it in session Create a multi-part form and leave the items in viewstate Each has its benefits.

I recommend making a base class which inherits from System.Page. Then have your page code behind inherit from that. Then, inside the base class, create a property that is a reference to your object.

For example, a like this: public class BasePage : System.Web.UI. Page { public Foo CurrentFoo { get { return (Foo)Session"FooSessionObject"; } set { if(Session"FooSessionObject"==null) { //instantiate a new one Session"FooSessionObject" = new Foo(); } Session"FooSessionObject" = value; } } } Then, from anywhere in any page, just do a CurrentFoo. And you will have access to any of the properties.

This makes for nice and clean code behinds.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions