HtmlTextWriter Constructors

Definition

Initializes a new instance of the HtmlTextWriter class.

Overloads

HtmlTextWriter(TextWriter)

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

HtmlTextWriter(TextWriter, String)

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

HtmlTextWriter(TextWriter)

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

C#
public HtmlTextWriter(System.IO.TextWriter writer);

Parameters

writer
TextWriter

The TextWriter instance that renders the markup content.

Examples

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.

C#

// 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);
    }
}

Remarks

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.

See also

Applies to

.NET Framework 4.8.1 a ďalšie verzie
Produkt Verzie
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

HtmlTextWriter(TextWriter, String)

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

C#
public HtmlTextWriter(System.IO.TextWriter writer, string tabString);

Parameters

writer
TextWriter

The TextWriter that renders the markup content.

tabString
String

The string to use to render a line indentation.

Examples

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.

C#

// 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);
    }
}

Remarks

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.

See also

Applies to

.NET Framework 4.8.1 a ďalšie verzie
Produkt Verzie
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1