Visual Basic Concepts
Now it's time to refresh your memory by taking a look back at the Customers page.
The HTML for the Customers page is generated by the code you entered in the Private Sub ShowIDs_Respond event procedure. Part of the code inserts a hyperlink on every row of the HTML table. Each row is a different customer and the hyperlinks link to the customer detail page for that customer. The code that generates the hyperlinks contains this syntax:
"<a href=""" & URLFor("Detail", CStr(rs1("contactID"))) & """>"
At run time, this code will create a hyperlink that looks something like this:
<a href="Webclass1.ASP?WCI=Detail&WCE=1">
A hyperlink usually moves to a web site — such as <a href="http://www.mycompany-inc-10.com">. In this case, the generated hyperlink will tell the system to go to the Detail webitem (WCI=Detail) and launch the UserEvent event with the EventName parameter set to 1 (WCE=1).
As the hyperlink is generated for each row of the table, the webclass event name (WCE) is set to a new ContactID value. Here is more of the HTML that the code creates and sends to the browser. These are the first two lines of the HTML table:
<table border=1 width=90% cellpadding=3>
<TR>
<TD>1</td>
<TD><a href="Webclass1.ASP?WCI=Detail&WCE=1">Nancy Davolio</a></td>
<TD>Cascade Coffee Roasters</td><TD>(206) 555-9857</td>
</tr>
<TR>
<TD>2</td>
<TD><a href="Webclass1.ASP?WCI=Detail&WCE=2">Janet Leverling</a></td>
<TD>Northwind Traders</td><TD>(206) 555-3412</td>
</tr>
In this HTML, the WCE= syntax indicates that a webitem’s UserEvent event (WCE) will be run when this link is clicked. The value that follows (in this case, a number) is the eventname for the event. For the first row of the table above, the eventname is 1, and for the second row, the eventname is 2. (If you had used a different database key, such as lastname, the eventname for the first row would be "Davolio," and for the second row would be "Leverling.")
In order for these event names to be processed, you must write code in a procedure known as the UserEvent procedure. UserEvent is fired whenever the webclass is run with the WCI= and WCE= values specified.
For our example, the actions the webclass must take in the UserEvent code are the following:
To write code to process the user event
Private rs2 as New ADODB.Recordset
If cn1.State = adStateClosed Then
ConnectMe cn1
End If
rs2.Open "select * from contacts where contactID=" & EventName, _
cn1, adOpenStatic, adLockReadOnly
Note A hyperlink syntax of <a href="Webclass1.ASP?WCI=Detail&WCE=1">Nancy Davolio</a>
would cause the Detail template’s UserEvent procedure to be called with the EventName parameter set to 1 (WCE=1
). In that case, the code above will retrieve all records from the contacts table where contactID is 1.
Detail.WriteTemplate