With Christmas fading to nothing more than a pleasant memory (except around the waistline where the consequences of unbridled gustatory abandon has left its seasonal evidence) we need to get fit again by leaping into an Active Server Page technology workout.
So let’s get fancy. Suppose we want to let the user choose the size of an array of radio buttons on a Web page and we want each button to be linked to client-side JavaScript. This means that we’ll need to create the array on the fly and generate a handler for each button in the array. Here’s a Web page that we’ll use to specify the size of the array:
1
Load this page and fill in the form entering, say, seven in the Rows field and six in the Columns field, and hit submit. This will create an HTTP request that will request array2.asp. This page looks like (for brevity we’ve only shown the code in the body and included line numbers for reference):
2 MaxRows = Request.Form(“rows”)
3 MaxCols = Request.Form(“cols”)
4 For intR = 1 to MaxRows
5 For intC = 1 to MaxCols
6 %>
7
8 OnClick = “Button_Click()”>
9
10
11
12
13
14 For intR = 1 to MaxRows
15 For intC = 1 to MaxCols
16 %>
17 SubButton_Click()
18 MsgBox “That is column , row .”
19 End Sub
20
21 Next
22 Next
23 %>
24
Here’s where we meet a major architectural feature of ASP: The IIS Object Model. The model is based on six core objects: Application, ObjectContext, Request, Response, Session and Server. Each one of these objects has its own events, properties, methods and collections (objects that contain a set of related objects).
In the ASP page above, lines 2 and 3 use the Request object to retrieve the arguments submitted by the form in the first Web page using the HTTP POST method. The Request object gives you access to the HTTP header and body and the “Form” object is the collection of all the POST items. Note that “Request.Form” is an abbreviated version of “Request.Form.Item” – the “Item” property is used to get a specific element in the collection by name. This means that we could have written lines 2 and 3 more properly as:
2 MaxRows = Request.Form.Item("Rows")
3 MaxCols = Request.Form.Item(“Cols”)
This code retrieves the arguments by their explicit names, that is “Rows” and “Cols,” respectively.
If we didn’t know the names but knew that the order of the arguments, then we could use the following code to retrieve the correct values:
2 MaxRows = Request.Form. (Request.Form.Key(1))
3 MaxCols = Request.Form. (Request.Form.Key(2))
The “Key” property is used to get items by number. If we had had a variable number of arguments to handle then we could get a count of how many arguments are in the Request object using:
NumArgs = Request.Form.Count
The array2.asp Web page consists of sections of scripting and other sections HTML content. The scripts are framed by “”. But we also have scripting inside the tags “ “. Our generated VBScript (to be executed on the browser) will be inside these tags.
Get these files from www.gibbs.com/021223; put the ASP page in a server subdirectory where it can be executed (put the form that requests the page in the same directory for the sake of simplicity). Send your variables to gearhead@gibbs.com.




