HtmlTextWriter Constructor (TextWriter, String)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Initializes a new instance of the HtmlTextWriter class with a specified tab string character.

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

Public Sub New (
	writer As TextWriter,
	tabString As String


Type: System.IO.TextWriter

The TextWriter that renders the markup content.

Type: System.String

The string to use to render a line indentation.

The HtmlTextWriter overload of the HtmlTextWriter(TextWriter, String) constructor uses tabString when indentation of a line is necessary. It calls the TextWriter.TextWriter(IFormatProvider) base constructor to initialize the new instance.

The following code example demonstrates how to use the HtmlTextWriter(TextWriter) constructor to create a custom HtmlTextWriter object named StyledLabelHtmlWriter. When the MyPage custom class, which is derived from the Page class, is requested by a client browser, it uses the StyledLabelHtmlWriter class to render its content to the output stream.

' A custom class that overrides the CreateHtmlTextWriter method.
' This page uses the StyledLabelHtmlWriter to render its content.  
<AspNetHostingPermission(SecurityAction.Demand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermission(SecurityAction.InheritanceDemand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Class MyPage
    Inherits Page

    Protected Overrides Function CreateHtmlTextWriter(ByVal writer As TextWriter) As HtmlTextWriter
        Return New HtmlStyledLabelWriter(writer)
    End Function 'CreateHtmlTextWriter
End Class 'MyPage

.NET Framework
Available since 1.1
Return to top