You can associate tags in the HTML code returned by the WebClass with custom
WebItem objects of the WebClass, and thus define special events that your IIS
application can react to. To implement a WebItem, follow these steps:
STEP BY STEP
17.2 Implementing a WebItem
-
Right-click the Custom WebItems folder in the IIS project window’s left-hand
pane to bring up the shortcut menu.
-
Choose Add Custom WebItem from the shortcut menu.
-
Type the name you want for the custom WebItem.
-
In the Start event of the WebClass, generate HTML code that uses the URLFor
function to create a hyperlink for the new WebItem. The user can click the hyperlink
to invoke the WebItem’s event. Listing 17.9 shows an example of how to use
the URLFor function to embed a custom URL for your WebItem event in the HTML that
you send to the browser.
LISTING 17.9
FRAGMENT OF A WEBCLASS_START EVENT PROCEDURE THAT USES THE URLFOR FUNCTION TO
EMBED A REFERENCE TO A CUSTOM WEBITEM IN HTML CODE RETURNED TO THE BROWSER
Private Sub WebClass_Start()
With Response
‘...preliminary stuff...
‘...
‘...
.Write "<A HREF=""" & _
URLFor(SvcExcellent) & _
""">Excellent</A><BR>"
‘...more stuff...
‘...
‘...
End With
End Sub
The call to URLFor in the example assumes that the project contains a custom WebItem
known as SvcExcellent. The HTML returned to the browser would contain a URL computed
for the WebItem that would work from the user’s location. As far as the
user’s browser is concerned, the hyperlink would be a normal link implemented
with the <A HREF=… tag format in HTML.
-
Double-click the new WebItem to add code to its Respond event procedure. The
code that you put here will react to the user’s choice in some manner. Perhaps
the code will make an entry in a database on the server, perhaps it will send
an email to someone in your organization, or perhaps it will send a new page to
the user’s browser by calling the WriteTemplate method of an HTML template.
Listing 17.10 shows one such possible use of a WebItem’s Respond event.
LISTING 17.10
USING A WEBITEM’S RESPOND EVENT TO SET SOME CLASS-LEVEL VARIABLES AND SEND
A TEMPLATE TO THE USER, AND THE USE OF THOSE VARIABLES IN THE PROCESSTAG EVENT
PROCEDURE OF THE TEMPLATE
Private Sub SvcExcellent_Respond()
strServiceColor = POORCOLOR
strServiceDescription = "Poor service."
tmpSurvey.WriteTemplate
End Sub
Private Sub tmpSurvey_ProcessTag(ByVal TagName As String,
TagContents As String, SendTags As Boolean)
LISTING 17.10
USING A WEBITEM’S RESPOND EVENT TO SET SOME CLASS-LEVEL VARIABLES AND SEND
A TEMPLATE TO THE USER, AND THE USE OF THOSE VARIABLES IN THE PROCESSTAG EVENT
PROCEDURE OF THE TEMPLATE
Select Case UCase$(TagName)
Case UCase$(tmpSurvey.TagPrefix) & "GREETING"
TagContents = strServiceDescription
Case UCase$(tmpSurvey.TagPrefix) & "FORECOLOR"
TagContents = "#0FF64" ‘a dark green
Case UCase$(tmpSurvey.TagPrefix) & "BACKCOLOR"
TagContents = strServiceColor
End Select
SendTags = False
End Sub
In the example of Listing 17.10, the Respond event sets some Private variables
of the WebClass and then calls the WriteTemplate method of the HTML template.
The ProcessTag event procedure of the template then uses the variables to dynamically
change the appearance of the Web page sent to the browser.