Presentation is loading. Please wait.

Presentation is loading. Please wait.

Application Object Controlling the Application Application Object Controlling the Application.

Similar presentations


Presentation on theme: "Application Object Controlling the Application Application Object Controlling the Application."— Presentation transcript:

1 Application Object Controlling the Application Application Object Controlling the Application

2 Application Object Application Object is created to represent an instance of an ASP application. Application Object is the fundamental object that is used to start and manage ASP applications. Application Object is a single object that can accessed by any user of that application

3 Application Object Information can be shared to all users in the application Session Objects,The individual users, represented by Session Objects, can read and update the application object as needed. The application object is controlled in the GLOBAL.ASA file

4 Application Object

5 The Application object as well as the other ASP objects, follows the familiar Object.method Application.method

6 Application Object The application objects have two events –Application_OnStart : Initiated when the ASP application is first started. –Application_OnEnd : Initiated when the ASP application is terminated.

7 Declaring Application-Level Variables Application Object-level variables are accessible by all user ov an application and share information common to all users. Application-level variables can be defined as needed in any ASP file, not just in the Application_OnStart and Application_OnEnd events of the GLOBAL.ASA file.

8 Scope of Variables in ASP Variables have two level of scope in ASP. –Page-level variables : are defined by a scripting language within an ASP scripts, and only has scope as that page is being processed. –object-level variables : exists in two forms session level : are used to pass variables from page to page fot a specifis user application level : are used to share commom information between all users.

9 Declaring Variables To declare a variable, use the following syntax: ObjectLevel(VarName) where ObjectLevel is the Application or Session Object and VarName is the name of the variable Example Application(“myAppWelcomeStr”) = “Welcome”

10 Example 1 : Global.asa Declaring an application-level to set a welcome message for all users in the application Sub Application_OnStart Application(“myWelcomeStr”)=“Welcome to my Homepage” Application(“myTitle”)=“ASP Corporation.” End Sub

11 Example 1 : ASP file

12 Example 2 : Global.asa Sub Application_OnStart Application(“counter”)= 1 End Sub Sub Session_OnStart Dim userCounter userCounter = Application(“counter”) + 1 Application(“counter”) = userCounter End Sub

13 Application_OnStart Event The Application_OnStart event is executed before any user or session event is trigged. So, any attempt to call a Session, Response, or Request object will be generate a fatal runtime error. Sub Application_OnStart …….Your application initialization code here End Sub

14 Application_OnEnd event The Application_OnEnd event occurs when the Web server terminates the Application. Sub Application_OnEnd …….Your script here. End Sub

15 Controlling Application-Level variable with Method The Application object has two methods to control variable access. –Lock : Prevent other users from changing Application object properties. –UnLock : Enables other users to modify the Application object properties.

16 Example 3 : Lock, UnLock Method <% Application.Lock Application(“vDueDate”)=Request.Form(“txtDueDate”) Application.UnLock %> This Application was processed on

17 UnLock Method Unlock is called when : –the page was finished processing –The script processing for a page times out (specific by session object)

18 Using Array at the Application Level Good way of storing information and making it available to all pages in your ASP application. Because this is static information, populating and array once from database conserves resources and processing power and saves you from having to make a database call for request.

19 Example 4 : Array in Global.asa Sub Application_OnStart Dim aMyAppTraining(4) aMyAppTraining(1) = “Using Active Server Pages” aMyAppTraining(2) = “Internet Architecture : The Basics” aMyAppTraining(3) = “Content management” aMyAppTraining(4) = “Internet Application workflow” Application(“aTraining”) = aMyAppTraining End Sub

20 Example 4 : Any ASP file (index.asp) <% Dim aLocalTrainingArray aLocalTrainingArray = Application(“aTraining”) aLocalTrainingArray(4) = “MY New Class” iClass = Ubound(aLocalTrainingArray) For i = 1 to iClass Response.Write(aLocalTrainingArray(i) & “ ”) Next %>

21 Example 4 : Result


Download ppt "Application Object Controlling the Application Application Object Controlling the Application."

Similar presentations


Ads by Google