Page 238 - DCAP408_WEB_PROGRAMMING
P. 238
Web Programming
Notes 4:
5: Sub Session_OnStart()
6: Session(“LogonTime”) = Now()
7: Session(“Name”) = “”
8:
9: Dim aPi(2)
10: aPi(0) = 3
11: aPi(1) = 1
12: aPi(2) = 4
13: Session(“Pi”) = aPi
14: End Sub
Listing above displays the OnStart event handlers for the Session and Application objects. The
Application object’s OnStart event handler begins on line 1. A single application variable, LastPost,
is initialized to a blank string (line 2). The Session object’s OnStart event handler begins on line
5. Line 6 creates a session variable named LogonTime that is initialized to the Web server’s
current date and time. Next, a session variable, Name, is created and initialized to an empty
string (line 7). Line 9 creates aPi, an array, and lines 10 through 13, set the three elements of aPi.
Line 13 creates the final session variable, setting it equal to aPi.
Notes Note the syntax for creating an event handler (lines 1 and 5). First, a subroutine is
created and named with the object’s name, followed by an underscore, and then followed
by the event name. Because the OnStart event passes in no parameters, no arguments are
in the event handler definition.
Whenever these events fire, the functions in above Listing are executed. The OnStart event
for the Session object occurs whenever a new visitor (one that does not already have a
Session instance) arrives at the site. If your Web site experiences a lot of traffic, this event
can fire hundreds, or even thousands of times an hour. The Application’s OnStart event,
however, fires only once, right before the first Session is created. If you restart your Web
server, though, the next visit after restarting causes the Application object’s OnStart event
to fire.
Self Assessment
Fill in the blanks:
11. An application on the Web may be a group of.
12. An ASP-based application is defined as all the .asp files in a directory and its subdirectories.
13. …………………… contains all of the objects added to the session with the <OBJECT> tag.
9.5 ASP the Global.asa file
The Global.as a file is an optional file that can contain declarations of objects, variables, and
methods that can be accessed by every page in an ASP application.
232 LOVELY PROFESSIONAL UNIVERSITY