HtmlTextWriter Constructores

Definición

Inicializa una nueva instancia de la clase HtmlTextWriter.

Sobrecargas

Nombre Description
HtmlTextWriter(TextWriter)

Inicializa una nueva instancia de la HtmlTextWriter clase que usa una cadena de tabulación predeterminada.

HtmlTextWriter(TextWriter, String)

Inicializa una nueva instancia de la HtmlTextWriter clase con un carácter de cadena de tabulación especificado.

HtmlTextWriter(TextWriter)

Inicializa una nueva instancia de la HtmlTextWriter clase que usa una cadena de tabulación predeterminada.

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

Instancia TextWriter de que representa el contenido de marcado.

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar el HtmlTextWriter(TextWriter) constructor para crear un objeto personalizado HtmlTextWriter denominado StyledLabelHtmlWriter. Cuando una clase cliente solicita la MyPage clase personalizada, que se deriva de la Page clase , usa la StyledLabelHtmlWriter clase para representar su contenido en el flujo de salida.

// 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

Comentarios

La HtmlTextWriter sobrecarga del HtmlTextWriter(TextWriter) constructor usa la DefaultTabString constante cuando es necesaria la sangría de una línea. Llama a la HtmlTextWriter(TextWriter, String) sobrecarga para inicializar la nueva instancia.

Consulte también

Se aplica a

HtmlTextWriter(TextWriter, String)

Inicializa una nueva instancia de la HtmlTextWriter clase con un carácter de cadena de tabulación 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

TextWriter que representa el contenido de marcado.

tabString
String

Cadena que se va a usar para representar una sangría de línea.

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar el HtmlTextWriter(TextWriter) constructor para crear un objeto personalizado HtmlTextWriter denominado StyledLabelHtmlWriter. Cuando una clase cliente solicita la MyPage clase personalizada, que se deriva de la Page clase , usa la StyledLabelHtmlWriter clase para representar su contenido en el flujo de salida.

// 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

Comentarios

La HtmlTextWriter sobrecarga del HtmlTextWriter(TextWriter, String) constructor usa tabString cuando es necesaria la sangría de una línea. Llama al TextWriter.TextWriter(IFormatProvider) constructor base para inicializar la nueva instancia.

Consulte también

Se aplica a