VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

VB .NET - Learn Visual Basic .NET

Systems Analysis - System analysis and Design tutorial for Software Engineering

You are here: Visual Basic > Advanced VB6 tutorial > Chapter 17

Substitution Tags

You can use substitution tags in IIS applications to easily add increased power to Web application development by making your pages more dynamic.

To use substitution tags with an HTML template, you need to perform two general activities:

  • Place substitution tags in the HTML template file.

  • Write code in the IIS project in the corresponding template object’s ProcessTag event procedure to substitute programmatically determined content for the substitution tags.

  • Make sure that you have included a call to the WriteTemplate method of the template object in the WebClass’ Start event procedure, as mentioned earlier in the section titled "Programming with an HTML Template."

The following paragraphs discuss these activities in more detail. You embed substitution tags in a WebClass’ HTML template file in places where you would like to dynamically control the contents of the file. For instance, you might want to make certain text dynamic, or perhaps certain HTML formatting such as font size or background color.

Listing 17.6 shows a snippet of HTML code without any substitution tags.


<BODY bgColor=#6496AF>
<FONT Color=#0FF64</FONT>
<H1>HTML Template demo</H1>
Hello from Beijor
Listing 17.7 shows the same snippet with substitution tags.
<H1>HTML Template demo</H1>

Note that all substitution tags in the HTML template for a WebClass begin with the same prefix (WC@ in the example). The WebClass uses the prefix to identify substitution tags so that it can process them in the corresponding template object’s ProcessTag event. You treat the substitution tags syntactically just like you would standard HTML formatting tags (using the <TAG>TagValue</TAG> paired format).

Listing 17.8 shows the text of the ProcessTag event procedure for a WebClass template object.


Private Sub tmpMyFirst_ProcessTag _
(ByVal TagName As String, _
TagContents As String, _
SendTags As Boolean)
Select Case UCase$(TagName)
Case UCase$(tmpMyFirst.TagPrefix) & "GREETING"
TagContents = "Hello from Beijor"
Case UCase$(tmpMyFirst.TagPrefix) & "FORECOLOR"
TagContents = "#0FF64" ‘a dark green
Case UCase$(tmpMyFirst.TagPrefix) & "BACKCOLOR"
TagContents = "#6496AF" ‘a blue-gray
End Select
SendTags = False
End Sub

The particular event procedure of this example would in fact process the tags of Listing 17.7. When the WebClass prepares to send the HTML template to a browser, it reads all the substitution tag pairs and passes one pair at a time to the ProcessTag event. The ProcessTag event procedure takes three parameters:

  • TagName is the parameter that gives the name of the tag that is being processed.

  • TagContents is the parameter that enables you to both read the current contents of the tag and to change the contents.

  • SendTags is a Boolean parameter that enables you to determine whether the substitution tags get reprinted in the HTML output.

    Doing so would enable you another level of tag processing. You will usually let this parameter take its default value of False.


<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © | All Rights Reserved