Events Methods collections

In ASP each virtual
directory on the server is an application.All the pages in that directory are
part of that application.Until recently , existing webtechonologies provided
cookies or hidden form fields.But ASP provides  Application object &
Session objects .Application object allows you to tie all the pages in a single
website into a consistent web application.A PWS has many number of Applications.Each
application has its own Application object.One of the features of application
is that you can store information that is available to all the clients that
are accessing the application.These variables are known as application-scope
variable.The information about these variables are stored in file global.asa
,a text file under root directory.

Asp Application Object Events

– This event is initiated when the ASP application is first started.

Eg.Store the following
code in global.asa file.

language = “VBScript” RUNAT = “Server”>

Sub Application_OnStart

  Application(“TestVar”) = 0

End Sub


– initiated when application is terminated.

Sub Application_OnEnd

  ‘Some code……

End Sub


Asp Application Object Methods

1) Lock
– prevents clients -other than one currently accessing it- from modifying the
variables stored in the application object.

– removes the,Enable other clients to modify variables stored.

Eg.Save the following
code in appvar.asp file.


<head><title>Application variable


Example for Application variable<br>

Let’s set value to application variable<br>



Application(“TestVar”) = “Test String”



To view new variable <A href=”appvar.asp”>click



– The Application.Contents.Remove method deletes an item from a collection.

For Eg


Application(“TestVar”) = “Test String”

Application(“AnotherVar”) = “Another String”




Application Object Collection

– contains all the variables that have been added to Application via script
in global.asa.We can retrieve the values using following code.


For each item in Application.contents




If you assign
a variable with the Server.CreateObject method, the variable will be a member
of the Application.Contents collection.

For eg.

Set Application(“ObjConn”) = Server.CreateObject(“ADODB.Connection”) %>

– contains the names of all objects added via the <object> tag in global.asa.The
objects declared in the Global.asa file are not created until the server processes
a script that calls that object.

For eg.

RUNAT=Server SCOPE=Application ID=objConn PROGID=”ADODB.Connection”>



This example creates
an Application object objConn by using the ProgID parameter. The objects declared
in the Global.asa file can be used by any script in the application.


Leave a Comment