![]()
|
|
|||||||||||||
|
|
Scope and lifetime of variablesIn ASP, the scope of variables within the code of a page does not depend on the language we use. This scope is based on these two rules:
Anyway, a variable is destroyed once the script has been executed. The lifetime of an ASP variable is therefore limited to the execution context of the script in which it has been defined. Exchanging variablesAccording to the previous paragraph, it seems not to be possible to exchange variables between ASP pages, but actually this problem can be solved. The GET methodThis is this easiest solution. It consists of passing the variable via the URL of the page that must get it. This solution is very convenient for redirects and links:
In this example,
The drawback of this method is that we have to add systematically the string "?var1=..." to all links. The Application objectWe should use his method only when we want to define variables available to all ASP scripts. Application variables are always available, no matter the page or the visitor. We can consider application variables are global variables. An example of this was given in the previous chapter. Using this object implies some constraints (see the chapter dedicated to this object). SessionsThis is maybe the best method. Sessions are used to store user-specific variables. Session variables are available to all pages of an ASP application. For instance, we use session variables to store logins and passwords for users:
We specify a timeout for sessions: when the session is over, all session variables are destroyed. The use of sessions if often related to the use of cookies: it may not be possible to use sessions with non cookie-compliant Web browsers. ReferencesThe W3Schools Web site |
|||||||||||||
|
Copyright © 2000-2001 themanualpage.org - This site is submissive to the terms of the GNU GPL and FDL licences. |
||||||||||||||