ASP.NET session variables, cookies, query string parameters, etc.
Part one of a five-part series of blogs

There is a range of techniques for remembering information in ASP.NET across pages and even sessions, including session variables, cookies, query string parameters and crosspage postback. This blog explains how to use each of these techniques, together with the pros and cons of each.

  1. Remembering State between Pages (this blog)
  2. Passing Data by Query String in the URL
  3. Passing Data using Session Variables
  4. Using Cookies to Remember Things
  5. Cross-Page Postback

This page is part of an online tutorial in ASP.NET.  We're also happy to train you in person in ASP.NET!

Posted by Andy Brown on 16 October 2012

You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Remembering State between Pages

I've just blogged about remembering state within a page; this blog shows how to pass information between pages.

You can download the Visual Basic or C# files for all of these examples.

Four Different Methods Available

There are 4 main ways to pass information between pages of an ASP.NET website:

Method Notes
Query string parameters Bits of information passed from one website to another in the URL (the website address).
Session variables Values which exist for as long as a user is logged on to a website.
Cookies Text files held on a user's computer for a fixed or indefinite period.
Cross-page postback A special way of passing information between naturally linked pages.

There's no clear answer to which of these is the best method, other than to say that often it's best in ASP.NET to do as much as possible on a single page to avoid having to pass information between pages in the first place.

Our Example Pages

To keep things really simple, this blog just shows you how to pass two bits of text information from one page to another:

Task form with 4 buttons

You can fill in a couple of fields, then click on one of four buttons to transfer the information entered to another form.


When you click on any one of the four buttons at the bottom of the page, you'll see the results on a second form:

Results of search - two strings

The results of clicking on the button above. We won't worry for the purposes of this blog what we'd do with these two pieces of information.

Creating a Shared Enumeration for Determining the Method Used

Because we can click on one of 4 different buttons in the above form, we need some way to determine which was used.  To do this, we'll create an enumeration in VB:

Public Class clsShared

Public Enum TransferMethod


NotSet = 0

QueryString = 1

SessionVariables = 2

Cookies = 3


End Enum

End Class

Or in C#:

public class clsShared


public clsShared() {}


public enum TransferMethod {

NotSet = 0,

QueryString = 1,

SessionVariables = 2,

Cookies = 3



For both VB and C# this is contained in a separate class called clsShared

Class called clsShared

Put your clsShared.cs or clsShared.vb class inside the App_Code folder.


With all of that preamble out of the way, let's begin by looking at passing information through the query string of a web page.

This blog has 0 threads Add post