Session variables are evil. Quite evil. We should strive to create our ASP pages without the use of session variables. However, session variables make it easy to pass information from one ASP page to another. It is recommended, however, that you use the querystring or forms to pass information from one ASP page to another, when possible. (There is an article on Four Ways of Passing Information From One ASP Page to Another.)
When passing strings or numbers, using a form or the querystring is a viable option. Many developers, though, think that they need to use session variables to pass arrays from one ASP page to another. This is far from the truth! To pass arrays, though, we have to use a bit of clever coding.
Before we begin, let's set up the situation. We have two ASP pages,
CreateArray.asp we will create an array of some size, enter some values, and allow this information to be passed to
ReceiveArray.asp through both the querystring and through the use of a form. In
ReceiveArray.asp, we will read in the array being passed in and display it.
Let's start by creating the array in
Now, to store the array contents in the querystring, we will loop from
UBound(aWeekDays). For each element, we'll add an item to the querystring, having the array name, an equals sign, and then the value of the particular array element.
We can also pass the contents of an array through a form, using the
INPUT tag. When using a form, we want to create N
HIDDEN INPUT tags, given N elements in our array. Each
INPUT tag will have the same
NAME but different
When the above form is submitted, the array information will be passed to
ReceiveArray.asp via the POST METHOD. A screenshot of
CreateArray.asp can be seen at the end of this article.
Now that we've looked at how to encode the array to pass it to
ReceiveArray.asp, let's examine how we will decode the array. Part 2 will delve into that topic!