This documentation is archived and is not being maintained.

ChtmlTextWriter Class

Writes a series of cHTML-specific characters and text to the output stream of an ASP.NET server control. The ChtmlTextWriter class provides formatting capabilities that ASP.NET server controls use when rendering cHTML content to clients.

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)

'Declaration
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class ChtmlTextWriter _
	Inherits Html32TextWriter
'Usage
Dim instance As ChtmlTextWriter

Compact HTML, or cHTML, is a subset of HTML 2.0, HTML 3.2, and HTML 4.0, and is designed to render on devices with limited memory and CPU power, along with small display screens, limited formatting capabilities, and a limited number of input options (such as a cell phone touch pad). Therefore, cHTML does not support the following:

  • JPEG images.

  • Tables.

  • Image maps.

  • Multiple character fonts and styles.

  • Background colors and images.

  • Frames.

  • Style sheets.

The ChtmlTextWriter class derives from the Html32TextWriter class and much of its functionality is provided by the Html32TextWriter and the base class for all markup text writers, which is the HtmlTextWriter class.

The following code example demonstrates how to create a class named CustomChtmlTextWriter that is derived from the ChtmlTextWriter class. It creates two constructors and overrides the OnAttributeRender method to prevent the bgcolor style attribute from being written to the output stream of the ChtmlTextWriter object. It also creates a class named ChtmlCustomPageAdapter that defines one method, CreateCustomChtmlTextWriter, which creates and returns an instance of the CustomChtmlTextWriter class. The CustomChtmlTextWriter then renders cHTML content for a page to devices with browsers that use cHTML markup.

' Create a class that derives from the 
' ChtmlTextWriter class. 
Imports System
Imports System.IO
Imports System.Web.UI
Imports System.Web.UI.WebControls.Adapters

Namespace AspNet.Samples.VB

    Public Class CustomChtmlTextWriter
        Inherits ChtmlTextWriter

        ' Create two constructors for the new 
        ' text writer. 
        Public Sub New(ByVal writer As TextWriter)
            MyClass.New(writer, DefaultTabString)
        End Sub 

        Public Sub New(ByVal writer As TextWriter, ByVal tabString As String)
            MyBase.New(writer, tabString)
        End Sub 

        ' Override the OnAttributeRender method to 
        ' not render the bgcolor attribute, which is  
        ' not supported in CHTML. 
        Protected Overrides Function OnAttributeRender(ByVal name As String, ByVal value As String, ByVal key As HtmlTextWriterAttribute) As Boolean 
            If (String.Equals("bgcolor", name)) Then 
                Return False 
            End If 

            ' Call the ChtmlTextWriter version of  
            ' the OnAttributeRender method. 
            MyBase.OnAttributeRender(name, value, key)

        End Function 
    End Class 

    ' Derive from the WebControlAdapter class, 
    ' provide a CreateCustomChtmlTextWriter 
    ' method to attach the custom writer. 
    Public Class ChtmlCustomPageAdapter
        Inherits WebControlAdapter

        Protected Friend Function CreateCustomChtmlTextWriter( _
         ByVal writer As TextWriter) As ChtmlTextWriter

            Return New CustomChtmlTextWriter(writer)

        End Function 
    End Class 
End Namespace

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Show: