HttpContext.Items[] vs Session[]
Since .NET first became available, passing data around during a request has become a lot easier. The ability to set a property has made that so. Still, there are times when setting a property just won’t do the trick.
One such time is getting data from the middle tier back up to the view separate from a DataBinding operation. That is, you databind a control to the middle tier and that method needs to set a value that will be used elsewhere in the view, not in the item that is being bound.
The natural, obvious tendency is to set a session variable. But there is a better way.
The problem with session variables is that they have to be cleaned up manually or they will hang around longer than we actually need them. This will use up more session memory than is required and can potentially cause side effects that will be difficult to debug.
Instead you can use the Items[] collection that is part of the HttpContext class. It works the same as a session variable, but it only hangs around for the duration of the request. Once the information is sent back to the browser, the variables that were set in the Items[] collection go away.
You might set your variable in the middle tier like this:
HttpContext.Current.Items["myVar"] = "Some Data Here";
And retrieve it later like this:
string myVar = (string)(HttpContext.Current.Items["myVar"]);
Other Related Items:
Tripp Lite TLP810NET Protect It! Surge Protector/Suppressor 8 outlets (3 Transformers) 10ft Cord 3240 JoulesTripp Lite's TLP810NET surge suppressor has 8 outlets, a 10-foot cord with a space-saving right-angle plug, and diagnostic LEDs. The unit has a surge ... Read More >
KEVIN.MURPHY SESSION.SPRAYStrong hold finishing spray
Jefferson in Paris [VHS]While American history buffs and Gwyneth Paltrow fans will want to own this movie just because, it actually compels the viewer to examine the life o... Read More >










I think it will be better if you use the ViewState object,in case you want to work in the page level.
The advantages of it, the value of the object exists while Post Backs.
@Mahmoud
Did you even read the article?
Tell me how using ViewState will allow me to pass variables around during the request.