O'Reilly logo

C# Primer: A Practical Approach by Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

7.10. Managing State: The Session Object

How do we correctly maintain values across posts back of a page? An HttpSessionState class object is maintained for each user that requests a page from an ASP.NET application. We store and retrieve values within this session object that we wish to persist across posts back. This object can be accessed through the page's Session property.

To initialize the values within the Session object, we need a hook into its initialization. The Session_Start() event handler provides just that hook. It is invoked once just prior to the start of a session. This is where we will insert our Anna, Pooh, and Miss count values that we increment with each appropriate user mouse click—for example,

 protected void Session_Start(Object ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required