Maintaining Session State

The main thing to understand here is that Web Forms (or the code behind the Web Forms) have to execute each time a request comes from the user. They process the request and then terminate. This makes things like module-level variables unusable for storing data that must persist for the entire session. Ah! A new word, session. Web applications use something called session state to maintain context between requests. The session state is maintained by IIS itself, so we don’t have to worry about the program terminating and losing its data.

The session exists outside the memory space of the executing code, so it is not lost. There is an intrinsic object called the Session object that is accessible from any Web Form’s code ...

Get ADO.NET Programming in Visual Basic™ .NET 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.