Page #33 (Chapter 4 - Introduction to WebClasses)

Chapter 4 - Introduction to WebClasses

Visual Basic Developers Guide to ASP and IIS
A. Russell Jones
  Copyright 1999 SYBEX Inc.

Understanding HTML Templates
WebClasses work closely with HTML templates. An HTML template is a standard HTML page with (optionally) some delimited fields that your WebClass can replace with custom information at runtime. You can call these special tags WebClass tags or custom tags. This is easier to see than to explain. Suppose you want to put a person's name in the title of an HTML page. You don't want to have separate pages for each person, you only want to change the title. The rest of the page should be the same regardless of who's viewing it. In a standard HTML page, the title goes into the <head> section between <title> and </title> tags:
<title>This is a title</title>
To display a different title for each user, you would create an HTML template with a single replaceable parameter:
     <title>Hello <wcName>Name</wcName></title>
When the WebClass processes the HTML template at runtime, it will find the <wcName> tag and raise a ProcessTag event. Inside the event procedure, you use a Case statement to determine which tag you're replacing.
Private Sub Template1_ProcessTag(ByVal TagName As String, _
    TagContents As String, SendTags As Boolean)
    Select Case TagName
    Case "wcName"
        TagContents = "Bob"
    End Select
End Sub
When this page displays in the browser, the title bar will contain Hello Bob.
This simple text replacement is a much more powerful concept than it appears at first glance. For example, suppose you have lists of customers, one list per salesperson. Whenever a salesperson signs on, you want to show only that person's customer list. You could write the HTML template so that it contained a WebClass tag, <wcCustomerList>, for the list. At runtime, you would replace the WebClass tag with the list for that salesperson. The page will display a customized list for every salesperson, based on their sign-on and that one replacement tag.
The reasoning behind HTML templates is that many programmers don't write HTML and don't want to write HTML. In theory, HTML templates make it easier to split development between graphic artists, Web designers, and programmers by separating the display code from the programming code. In practice, there's often a tight integration between the two. For many projects, there's also a point at which it becomes awkward, inconvenient, and often counterproductive to keep moving back and forth between a layout artist and a programming team. Usually, the programmer takes over the main responsibility at that point. Finally, in instances where the program code requires knowledge of the positions of objects on the screen, the layout/programming split becomes nonexistent.
Personally, I feel that programmers working in the Web medium need to learn the layout language. Part of the appeal of Visual Basic has always been the power it gave programmers to quickly lay out graphical interfaces. If you don't understand the layout language in the Web medium, you have abdicated that power. Some people will argue that the VB forms engine also writes "code" (in .frm files) that you don't need to understand; similarly, HTML editors provide drag-and-drop formatting capability for HTML code. That's a valid argument. So what's the difference? Maybe when the HTML editors get so good at writing code that they always do exactly what you expect, there won't be any difference. Meanwhile, this entire area is changing so rapidly that you should learn the layout language, if only to take maximum advantage of the medium.



Visual Basic Developer[ap]s Guide to ASP and IIS
Visual Basic Developer[ap]s Guide to ASP and IIS
ISBN: 782125573
EAN: N/A
Year: 2005
Pages: 98

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net