Share via


HTML Construction Methodology for Solution Sites

String concatenation is used extensively throughout the Solution Sites code to build the strings of HTML that are eventually written to the browser. The nature of HTML lends itself quite naturally to this technique, as the following examples show.

Given a hypothetical routine that produces HTML, named htmReturnsHTML, and a variable for "collecting" the accumulating HTML, named htmContent, the following examples show how intuitive it is to wrap, prepend, or append one string of HTML to another.

Wrap: htmContent = "<B>" & htmReturnsHTML() & "</B>"

Wrap: htmContent = "<P>" & htmContent & "</P>"

Prepend: htmContent = htmReturnsHTML() & htmContent

Append: htmContent = htmContent & htmReturnsHTML()

The file include\html_lib.asp contains many routines that have encapsulated these types of string concatenations. Some are quite simple, like the functions Bold and Italic. Others are more complex, like the routines provided for building HTML tables. For more information about the different categories of routines provided in the file include\html_lib.asp, see Categories of Routines used for Solution Sites.

Another important aspect of the HTML routines concerns styles, which are most often set by specifying attributes to the HTML elements. For example, the function RenderText takes two parameters: str and sAttList. The parameter str provides the basic string that is going to be wrapped in a FONT element. The parameter sAttList provides a list of attributes that will be associated with the FONT element, providing such characteristics as the type and size of the font to be rendered. The function RenderText consists of the following line of code:

RenderText = "<FONT" & sAttList & ">" & str & "</FONT>"

Notice how the value of the sAttList parameter is embedded within the starting FONT tag, in the position where element attributes occur. The strings you construct for the sAttList parameters that are used by many of the HTML routines are space-separated lists of attributes appropriate to the element with which they are being associated. They must begin with a space character so that the first attribute specified will be separated from the element tag itself.

Another way in which styles are specified occurs globally, in a Dictionary object accessible through the page variable MSCSSiteStyle. This dictionary contains numerous entries that provide styles to be applied in different contexts throughout the HTML produced by the Solution Sites code. For example, it is common to see a line of code like the following in the Solution Sites code (RenderLink is called 43 times), which shows the global link style being passed as the sAttList parameter to the RenderLink function:

htmContent = htmContent & RenderLink(urlLink, htmLinkText, _
                                     MSCSSiteStyle.Link) & BR

This technique allows you to easily make global changes to the styles used in your site. For more information about the global style settings, see Customizing Styles.

If suitable for the users of your site, you could implement client-side styles by using these global style dictionary entries to define CLASS and ID attributes for use with Cascading Style Sheet (CSS) files.

The preceeding RenderLink example illustrates another important aspect of the HTML construction infrastructure used by the Solution Sites: constants are provided for some of the simpler HTML tags, such as BR for "<BR>". Using these constants can make the code read more cleanly. For more information about these constants, see HTMLLib Constants.

Copyright © 2005 Microsoft Corporation.
All rights reserved.