Page.CreateHtmlTextWriter(TextWriter) Método

Definición

Crea un objeto HtmlTextWriter para representar el contenido de la página.

protected:
 virtual System::Web::UI::HtmlTextWriter ^ CreateHtmlTextWriter(System::IO::TextWriter ^ tw);
protected public:
 virtual System::Web::UI::HtmlTextWriter ^ CreateHtmlTextWriter(System::IO::TextWriter ^ tw);
protected virtual System.Web.UI.HtmlTextWriter CreateHtmlTextWriter (System.IO.TextWriter tw);
protected internal virtual System.Web.UI.HtmlTextWriter CreateHtmlTextWriter (System.IO.TextWriter tw);
abstract member CreateHtmlTextWriter : System.IO.TextWriter -> System.Web.UI.HtmlTextWriter
override this.CreateHtmlTextWriter : System.IO.TextWriter -> System.Web.UI.HtmlTextWriter
Protected Overridable Function CreateHtmlTextWriter (tw As TextWriter) As HtmlTextWriter
Protected Friend Overridable Function CreateHtmlTextWriter (tw As TextWriter) As HtmlTextWriter

Parámetros

tw
TextWriter

El objeto TextWriter utilizado para crear el objeto HtmlTextWriter.

Devoluciones

HtmlTextWriter o Html32TextWriter.

Ejemplos

En el ejemplo de código siguiente se usa el CreateHtmlTextWriter método para crear una instancia de un objeto personalizado HtmlTextWriter denominado MyHtmlTextWriter. El CreateHtmlTextWriter método se invalida en la MyPage clase , que se deriva de Page, de modo que MyHtmlTextWriter representa ASP.NET controles de servidor cuando se solicita la página. Tenga en cuenta que en este ejemplo se evitará el comportamiento del adaptador TextWriter .

namespace WebPage
{
   using System;
   using System.IO;
   using System.Web.UI;

   public class MyPage : Page
   {
      public MyPage():base()
      {
      }

      [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] 
      protected override HtmlTextWriter CreateHtmlTextWriter(TextWriter writer)
      {
         return new MyHtmlTextWriter(writer);
      }

      [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] 
      protected override void Render(HtmlTextWriter writer)
      {         
         // Write a Font control.
         writer.AddAttribute("color", "red");
         writer.AddAttribute("size", "6pt");
         writer.RenderBeginTag(HtmlTextWriterTag.Font);
         writer.Write("<br>" + "The time on the server:<br> " + System.DateTime.Now.ToLongTimeString());
         writer.RenderEndTag();
      }
   }

   public class MyHtmlTextWriter : HtmlTextWriter
   {
      public MyHtmlTextWriter(TextWriter writer):base(writer)
      {
         writer.Write("<font color=blue> 'MyHtmlTextWriter' is used for rendering.</font>");
      }
   }
}

Imports System.IO
Imports System.Web.UI

Namespace WebPage

    
   Public Class MyPage
      Inherits Page
      
      Public Sub New()
         MyBase.New()
      End Sub

      <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
      Protected Overrides Function CreateHtmlTextWriter(ByVal writer As TextWriter) As HtmlTextWriter
         Return New MyHtmlTextWriter(writer)
      End Function 'CreateHtmlTextWriter

      <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
      Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
         ' Writes a Font control.
         writer.AddAttribute("color", "red")
         writer.AddAttribute("size", "6pt")
         writer.RenderBeginTag(HtmlTextWriterTag.Font)
         writer.Write(("<br>" + "The time on the server:<br> " + System.DateTime.Now.ToLongTimeString()))
         writer.RenderEndTag()
      End Sub
   End Class
    

   Public Class MyHtmlTextWriter
      Inherits HtmlTextWriter
      
      Public Sub New(writer As TextWriter)
         MyBase.New(writer)
         writer.Write("<font color=blue> 'MyHtmlTextWriter' is used for rendering.</font>")
      End Sub
   End Class
End Namespace 'WebPage

Comentarios

El CreateHtmlTextWriter método crea a TextWriter través de la Browser propiedad del Request objeto asociado a la solicitud de página. Puede agregar una referencia a en HtmlTextWriter la browserCaps sección de configuración. Invalide el CreateHtmlTextWriter método para realizar una búsqueda personalizada.

Se aplica a

Consulte también