Page.HTMLEncode

Ee797279.c++_on(en-US,CS.10).gifEe797279.vb_off(en-US,CS.10).gif

Use this method to apply HTML encoding to the specified text string. Its typical use is to display the contents of text fields contained in the database in HTML. Characters in the string, such as "<" and "&" that have special meanings in HTML, are converted into their HTML equivalents, such as &lt; and &amp; so that they will be displayed correctly by the client browser.

Ee797279.important(en-US,CS.10).gif Important

  • This method is included for backwards compatibility with Site Server 3.0 Commerce Edition.

Definition

Function HTMLEncode(vtValue As Variant) As String

Parameters

vtValue

A String Variant that contains the text string to encode.

Return Values

If this method completes successfully, it returns a String that contains encoded HTML text.

Error Values

This method sets the Number property of the global Err object to S_OK (&H00000000) to indicate success and to standard COM error values to indicate failure. For more information about standard COM errors, see Standard COM Errors. Additional information may be available using the global Err object. In particular, the Description property may contain a text description of the error.

Remarks

If the text field to be displayed already contains HTML encoding, do not use the HTMLEncode method. For example, suppose your product_description field contains HTML-encoded text such as "The <I>Classic Diner Clock</I> brings the age of the &quot;Golden Oldies&quot; to your kitchen." This string uses the <I> tag to format italic text and the &quot; sequence to display quotation marks when displayed by the client browser. Because the string is already coded in HTML, you do not need to encode it again. Double-encoding the string would produce incorrect results.

The Page.HTMLEncode method is identical to the Page.Encode method, but the HTMLEncode method is the preferred name. The method is similar to Server.HTMLEncode except that the Page.HTMLEncode method handles NULL values by returning an empty string (the Server.HTMLEncode method fails when the vtValue parameter is NULL). This distinction is important because database queries can return NULL.

For more information about memory ownership issues related to COM property and method parameters, see Managing COM Parameter Memory.

Example

' oPage is a Commerce.Page object
Assume that the company_name field contains the name Freeman & Sons
' The following HTML example displays the contents of the company_name
' field as an <H1> tag:
<H1><% = oPage.HTMLEncode(companyinfo.company_name) %></H1>
' This example returns the following HTML string:

<H1>Freeman &amp; Sons</H1>

See Also

Page Object

Page.URLEncode


All rights reserved.