Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

HtmlTextWriter Constructor (TextWriter)

Initializes a new instance of the HtmlTextWriter class that uses a default tab string.

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

public HtmlTextWriter(
	TextWriter writer
)

Parameters

writer
Type: System.IO.TextWriter

The TextWriter instance that renders the markup content.

The HtmlTextWriter overload of the HtmlTextWriter(TextWriter) constructor uses the DefaultTabString constant when indentation of a line is necessary. It calls the HtmlTextWriter(TextWriter, String) overload 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 its CreateHtmlTextWriter method. 
// This page uses the HtmlStyledLabelWriter class to render its content.
[AspNetHostingPermission(SecurityAction.Demand,
    Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand,
    Level = AspNetHostingPermissionLevel.Minimal)]
public class MyPage : Page
{
    protected override HtmlTextWriter CreateHtmlTextWriter(TextWriter writer)
    {
        return new HtmlStyledLabelWriter(writer);
    }

}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1
Show:
© 2015 Microsoft