ASP   «Prev  Next»

Lesson 3ASP's objects and the browser-server dialogue
ObjectiveExplain how ASP's objects assist the browser-server dialogue.

ASP's Objects and the browser-server Dialogue

Once the browser and server are in communication with each other, they will work together to exchange data and commands as the user navigates the Web site. ASP's built-in objects provide standardized ways of reading, storing, accessing, and displaying this data, saving the programmer the work of custom-designing these routines. As explained in a prior lesson, ASP objects (Application, Request, Response, Server, and Session) are objects in the object-oriented sense: each can perform a specific type of action in a finite number of ways (Methods) on a particular type of data (Collections) and has modifiers, or attributes, that can be set (Properties). The purpose of a div is to divide up a web page into distinct sections, adding structural meaning.

Collections

A collection is similar to an array, but collections automatically adjust their size as items are added or deleted. You can refer to individual items by name or position number.
Here's an example of using a collection:

<%= Application("OrderNum") %>

This would be the same as writing:

<%= Application.Contents("OrderNum") %>

You can also loop through a collection using the For Each/Next statement from the last module. Where the number of items can vary, you can use a For/Next or Do While/Wend technique. You can reference individual items in a collection
  1. by name as in Response.Form ("FirstName") or
  2. by element number as in Response.Form (2).

Object properties

Properties are attributes of an object, rather than the data on which it operates. The Response object has a ContentType property , which specifies the type of data being sent to the browser. To set the content type of a Response object that will send a JPEG image, you could write:

<% Response.ContentType = "image/JPEG" %>

Object methods and event recognition

Methods are actions that objects can perform. For example, sending HTML code to a browser is an action. The Response object's method for this is Response.Write:

<%Response.Write "Hello World"%>

Events are occurrences in the system that are recognized by a program or object. Some ASP Objects are able to notice and act upon one or more events as they occur. The Session object, for example, has an event that recognizes when the server is starting a new user session; you can use this characteristic to run a specific ASP program whenever a new session is created.

ASP objects and multiple users?

Any Web site of interest to users can expect to host multiple users at one time. These users can request and view static Web pages without conflicts even if you aren't using ASP. However, once you incorporate interactivity on your Web site, your server will have to read, store, calculate and write data for more than one user at a time. ASP's Application, Session, and Server objects provide scalable ways to manage multiple users without repetitive customized programming.
We will examine those ASP objects later in the course. For the time being, just imagine that only one user at a time is connecting to our Web server.The next lesson describes the ASP Request object.