|
Querystrings
You
may find that you need to pass variables from one page to the next, and
one of the easiest ways to do this is through the use of a "querystring".
What is a "querystring"?
A querystring is a method of the "Response"
object that includes variable names and values that can be passed via a
link or Response.Redirect from one ASP page to another. I.E.:
a href="nextpage.asp?id=<%=ReportID %>"
OR
response.redirect "nextpage?id=" &
ReportID
This is very helpful if you don't have a form in
your current page to pass "hidden" information from it to
another page.
What are the rules?
- If using a "response.redirect" for
passing variables make sure your Buffers are set to TRUE
If you are going to use the "response.redirect" method
to pass variables from one page to the next, make sure you turn your
buffers on in the page that contains the "response.redirect"
method. You do this by adding the following code to the top of
your page (above any other ASP code):
Response.Buffer = TRUE
- Limit the number of passed variables
Recently I was working on a site that needed to pass a great
number of variables from one page to the next. And for the
first time I received a VERY ugly error message that had me totally
baffled until I realized that my "response.redirect"
string was TOO long! The error message was something like:
"Page not found"
And in the address bar in place of the page name I was passing the
variables to was the word "failed".
The only solution I could find, since I absolutely needed to pass
all these variables, was to assign them to "Session"
variables. In other words I took them out of my "response.redirect"
string and placed them in a Session. I.E.
Session("ReportID")
And this way the values in the variables were available for use in
subsequent pages until they would be overwritten when assigned
again. (The only thing about using Session variables is that
you need to make sure your Session does not time-out before they
have a chance to be used by the next page. If you think it is
possible that your Session might time-out, set your Session timeout
to a longer time than the default (20 minutes). You do this by
adding the following code to your home page or to your Global.asa"
Session.Timeout = 60
The "60" is 60 minutes. You can set it to whatever
length you think is necessary.
|