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

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

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

<Script
language = “VBScript” RUNAT = “Server”>

Sub Application_OnStart


  Application(“TestVar”) = 0


End Sub

</Script>

2)Application_OnEnd
– initiated when application is terminated.

Eg
Sub Application_OnEnd


  ‘Some code……


End Sub

Top




Asp Application Object Methods

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

2)UnLock
– removes the lock.ie,Enable other clients to modify variables stored.

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

<html>

<head><title>Application variable
test</title></head>

<body>

Example for Application variable<br>


Let’s set value to application variable<br>


<%

Application.Lock

Application(“TestVar”) = “Test String”


Application.UnLock


%>

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

</body>

</html>

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

For Eg

<%

Application(“TestVar”) = “Test String”


Application(“AnotherVar”) = “Another String”


   Application.Contents.Remove(TestVar)


%>

Top




Application Object Collection

1)Contents
– 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


   response.write(item)


next

%>

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”) %>


2)StaticObjects
– 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.

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


……….

</OBJECT>

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.

Top



Leave a Comment