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 ...

Get C# Primer: A Practical Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.