HtmlTextWriter Construtores

Definição

Inicializa uma nova instância da HtmlTextWriter classe.

Sobrecargas

Name Description
HtmlTextWriter(TextWriter)

Inicializa uma nova instância da HtmlTextWriter classe que usa uma string tab por defeito.

HtmlTextWriter(TextWriter, String)

Inicializa uma nova instância da HtmlTextWriter classe com um carácter de string tab especificado.

HtmlTextWriter(TextWriter)

Inicializa uma nova instância da HtmlTextWriter classe que usa uma string tab por defeito.

public:
 HtmlTextWriter(System::IO::TextWriter ^ writer);
public HtmlTextWriter(System.IO.TextWriter writer);
new System.Web.UI.HtmlTextWriter : System.IO.TextWriter -> System.Web.UI.HtmlTextWriter
Public Sub New (writer As TextWriter)

Parâmetros

writer
TextWriter

A TextWriter instância que gera o conteúdo da marcação.

Exemplos

O seguinte exemplo de código demonstra como usar o HtmlTextWriter(TextWriter) construtor para criar um objeto personalizado HtmlTextWriter chamado StyledLabelHtmlWriter. Quando a MyPage classe personalizada, que é derivada da Page classe, é solicitada por um navegador cliente, utiliza a StyledLabelHtmlWriter classe para renderizar o seu conteúdo no fluxo de saída.

// A custom class that overrides its CreateHtmlTextWriter method.
// This page uses the StyledLabelHtmlWriter class to render its content.
public ref class MyPage: public Page
{
protected:
   virtual HtmlTextWriter^ CreateHtmlTextWriter( TextWriter^ writer ) override
   {
      return gcnew HtmlStyledLabelWriter( writer );
   }
};

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

Observações

A HtmlTextWriter sobrecarga do HtmlTextWriter(TextWriter) construtor usa a DefaultTabString constante quando é necessária a indentação de uma linha. Chama a HtmlTextWriter(TextWriter, String) sobrecarga para inicializar a nova instância.

Ver também

Aplica-se a

HtmlTextWriter(TextWriter, String)

Inicializa uma nova instância da HtmlTextWriter classe com um carácter de string tab especificado.

public:
 HtmlTextWriter(System::IO::TextWriter ^ writer, System::String ^ tabString);
public HtmlTextWriter(System.IO.TextWriter writer, string tabString);
new System.Web.UI.HtmlTextWriter : System.IO.TextWriter * string -> System.Web.UI.HtmlTextWriter
Public Sub New (writer As TextWriter, tabString As String)

Parâmetros

writer
TextWriter

O TextWriter que gera o conteúdo da marcação.

tabString
String

A cadeia a usar para renderizar uma indentação de linha.

Exemplos

O seguinte exemplo de código demonstra como usar o HtmlTextWriter(TextWriter) construtor para criar um objeto personalizado HtmlTextWriter chamado StyledLabelHtmlWriter. Quando a MyPage classe personalizada, que é derivada da Page classe, é solicitada por um navegador cliente, utiliza a StyledLabelHtmlWriter classe para renderizar o seu conteúdo no fluxo de saída.

// A custom class that overrides its CreateHtmlTextWriter method.
// This page uses the StyledLabelHtmlWriter class to render its content.
public ref class MyPage: public Page
{
protected:
   virtual HtmlTextWriter^ CreateHtmlTextWriter( TextWriter^ writer ) override
   {
      return gcnew HtmlStyledLabelWriter( writer );
   }
};

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

Observações

A HtmlTextWriter sobrecarga do HtmlTextWriter(TextWriter, String) construtor é usada tabString quando é necessária a indentação de uma linha. Chama o TextWriter.TextWriter(IFormatProvider) construtor base para inicializar a nova instância.

Ver também

Aplica-se a