Wrapping up our ASP example

Opinion
Jan 13, 20033 mins

Last week we introduced the IIS Object Model and, specifically, the Request object, which gives you access to the HTTP header and body, and the Form collection, which provides access to all the POST’ed items.

We also outlined a wonderfully eccentric and fabulously pointless Web page that uses Active Server Scripting to create an array of radio buttons with individual scripts related to each button (download the code here).

To continue with our survey of the code: Lines 7 and 8 are HTML with in-line sections of Active Server Page (ASP) script that are replaced by the value of the variables referenced as the count of columns and rows (the variables ‘intC” and “intR”) are each looped through.

8 OnClick = “Button_Click()”>

This generates the following client-side HTML output, which is sent to the browser:

. . . and so on. This code defines an OnClick event that calls a unique function for each button. Lines 12 through 24 create the client-side scripted function for each button.

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

The loops starting in Line 14 for the rows and Line 15 for the columns create the code (we’ve assumed five columns and seven rows were requested) below. Note that the output from these loops will be between the tag (Line 24) in the generated content.

Sub Button11_Click()

MsgBox “That is column 1, row 1.”

End Sub

Sub Button21_Click()

MsgBox “That is column 2, row 1.”

End Sub

– Etc., etc. etc. –

Sub Button56_Click()

MsgBox “That is column 5, row 6.”

End Sub

Sub Button57_Click()

MsgBox “That is column 5, row 7.”

End Sub

So when you load the output page generated by the ASP page and click on a radio button, a message will be displayed announcing which button was clicked. Of course you could create any code you like for the body of each function.

This is a trivial example of ASP programming, but it illustrates some important features.

First, it shows you how ASP is woven into a document and how the results of the script replace and modify the regular HTML content.

Second, it illustrates that server-side ASP scripting can create client-side scripting. This can be incredibly useful where catalogs or directories are being displayed.

Moreover, in our example we created client-side VBScript but we could have created code in any client-side supported language or for any plug-in or browser service.

Finally, it shows how ASP can be used to generate complex, variable content. In this case we created client-side scripting but we could have created tables, lists, frames, etc.

This requires a different way of thinking about Web content because until the output leaves the server the scripting can treat the HTML content as nonlinearly, as needed, to create the required output.

Next week, we’ll wrap up our discussion of ASP. Send your objects to gearhead@gibbs.com.