HtmlTextWriter Konstruktory

Definicja

Inicjuje nowe wystąpienie klasy HtmlTextWriter.

Przeciążenia

HtmlTextWriter(TextWriter)

Inicjuje HtmlTextWriter nowe wystąpienie klasy, które używa domyślnego ciągu karty.

HtmlTextWriter(TextWriter, String)

Inicjuje HtmlTextWriter nowe wystąpienie klasy z określonym znakiem ciągu tabulatora.

HtmlTextWriter(TextWriter)

Inicjuje HtmlTextWriter nowe wystąpienie klasy, które używa domyślnego ciągu karty.

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)

Parametry

writer
TextWriter

Wystąpienie TextWriter , które renderuje zawartość znaczników.

Przykłady

W poniższym przykładzie kodu pokazano, jak za pomocą konstruktora HtmlTextWriter(TextWriter) utworzyć obiekt niestandardowy HtmlTextWriter o nazwie StyledLabelHtmlWriter. MyPage Gdy klasa niestandardowa, która pochodzi z Page klasy, jest żądana przez przeglądarkę klienta, używa StyledLabelHtmlWriter klasy do renderowania jego zawartości do strumienia wyjściowego.

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

Uwagi

Przeciążenie HtmlTextWriter konstruktora HtmlTextWriter(TextWriter) używa stałej, DefaultTabString gdy konieczne jest wcięcie linii. Wywołuje przeciążenie HtmlTextWriter(TextWriter, String) , aby zainicjować nowe wystąpienie.

Zobacz też

Dotyczy

HtmlTextWriter(TextWriter, String)

Inicjuje HtmlTextWriter nowe wystąpienie klasy z określonym znakiem ciągu tabulatora.

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)

Parametry

writer
TextWriter

Element TextWriter renderujący zawartość znaczników.

tabString
String

Ciąg używany do renderowania wcięcia wiersza.

Przykłady

W poniższym przykładzie kodu pokazano, jak za pomocą konstruktora HtmlTextWriter(TextWriter) utworzyć obiekt niestandardowy HtmlTextWriter o nazwie StyledLabelHtmlWriter. MyPage Gdy klasa niestandardowa, która pochodzi z Page klasy, jest żądana przez przeglądarkę klienta, używa StyledLabelHtmlWriter klasy do renderowania jego zawartości do strumienia wyjściowego.

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

Uwagi

Przeciążenie HtmlTextWriter konstruktora HtmlTextWriter(TextWriter, String) jest używane tabString , gdy konieczne jest wcięcie wiersza. Wywołuje on konstruktor podstawowy w TextWriter.TextWriter(IFormatProvider) celu zainicjowania nowego wystąpienia.

Zobacz też

Dotyczy