Share via


Initializing the htmPageContent Variable

As mentioned in Implementing the Main Subroutine for Solution Sites and Page Execution Model for Solution Sites, one of the responsibilities of the Main routine in a particular page you are authoring is to establish the value of the variable htmPageContent prior to returning. Once the Main routine has returned, execution proceeds to the page layout code, which uses the value of the variable htmPageContent as the HTML to be rendered in the content area of the page.

Many of the utility routines that exist in the various include files are designed to help create the HTML tags that end up within the string assigned to the variable htmPageContent. One particularly basic set of such routines can be found in the file include\html_lib.asp.

The following example shows a function from the file include\html_lib.asp that wraps the string passed to it in tags that will cause it to be rendered in bold font:

Function Bold(ByVal s)
    Bold = "<B>" & s & "</B>"
End Function

Suppose you have already initialized the variable htmPageContent to contain the string "To be or not to be" that you want to display in the content area of the page, and that you want the string to be rendered in bold font. You could call the function Bold as follows:

htmPageContent = Bold(htmPageContent)

The resulting string is now "<B>To be or not to be</B>".

Another function in the file include\html_lib.asp, named PTag, can be used to wrap a string in paragraph tags. If the new value of the variable htmPageContent is passed to the PTag function, the new value would be "<P><B>To be or not to be</B></P>".

These very simple functions illustrate an important aspect of the design of the utility routines designed to help create the value stored in the variable htmPageContent, and which follows naturally from the nature of HTML markup itself: the construction of the HTML that gets stored as a string in the variable htmPageContent should begin from the innermost, simplest aspects of the page, and build toward the more complex constructs. This methodology makes heavy use of string concatenation, but does provide a higher-level programming approach, allowing you to change styles globally later. It also has the advantage of allowing content to be cached. For more information about caching content, see Caching Solution Sites.

Consider the following, simplified example, which uses three functions to build a table:

Function WrapTable(ByVal s)
    WrapTable = "<TABLE>" & s & "</TABLE>"
End Function

Function WrapRow(ByVal s)
    WrapRow = "<TR>" & s & "</TR>"
End Function

Function WrapCell(ByVal s)
    WrapCell = "<TD>" & s & "</TD>"
End Function

Given the following four string values, these functions can be used to build a 2-by-2 table as shown below:

Dim sRow1Col1, sRow1Col2, sRow2Col1, sRow2Col2, htmTemp1, htmTemp2
sRow1Col1 = "r1,c1"
sRow1Col2 = "r1,c2"
sRow2Col1 = "r2,c1"
sRow2Col2 = "r2,c2"

htmTemp1 = WrapCell(sRow1Col1) & WrapCell(sRow1Col2)
htmTemp1 = WrapRow(htmTemp1)
htmTemp2 = WrapCell(sRow2Col1) & WrapCell(sRow2Col2)
htmTemp2 = WrapRow(htmTemp2)
htmPageContent = htmTemp1 & htmTemp2
htmPageContent = WrapTable(htmPageContent)

This code will produce the following string:

<TABLE><TR><TD>r1,c1</TD><TD>r1,c2</TD></TR><TR><TD>r2,c2</TD><TD>r2,c2</TD></TR></TABLE>

This string will render as follows:

r1,c1 r1,c2
r2,c2 r2,c2

For purposes of illustration, this example is simpler than the actual table building routines in the file include\html_lib.asp (RenderTable, RenderTableDataRow, and RenderTableHeaderRow), which are designed such that the data and the formatting attributes for the cells in a table are passed in the form of arrays, avoiding the need to explicitly wrap each cell in TD tags as shown in this example. Nevertheless, the example does show how the string value assigned to the variable htmPageContent is built from the inside out.

Reviewing the provided utility routines will give you an understanding of the functionality provided. The existing pages show how these utility routines are used to build the HTML content that is assigned to the variable htmPageContent in the various functions named Main, and then displayed in the content area in one of the two layout files template\layout1.asp or template\no_menu.asp (or in another layout file of your own design).

See Also

Implementing the Main Subroutine for Solution Sites

Page Execution Model for Solution Sites

Copyright © 2005 Microsoft Corporation.
All rights reserved.