Page.CreateHtmlTextWriter(TextWriter) Metodo

Definizione

Crea un oggetto HtmlTextWriter per eseguire il rendering del contenuto della pagina.Creates an HtmlTextWriter object to render the page's content.

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

Parametri

tw
TextWriter

Classe TextWriter utilizzata per creare l'oggetto HtmlTextWriter.The TextWriter used to create the HtmlTextWriter.

Restituisce

HtmlTextWriter

Oggetto HtmlTextWriter o Html32TextWriter.An HtmlTextWriter or Html32TextWriter.

Esempio

Nell'esempio di codice seguente viene utilizzato il CreateHtmlTextWriter metodo per creare un'istanza di un HtmlTextWriter oggetto personalizzato denominato MyHtmlTextWriter .The following code example uses the CreateHtmlTextWriter method to create an instance of a custom HtmlTextWriter object named MyHtmlTextWriter. CreateHtmlTextWriterViene eseguito l'override del metodo nella MyPage classe, derivata da, in Page modo che MyHtmlTextWriter esegua il rendering dei controlli server ASP.NET quando viene richiesta la pagina.The CreateHtmlTextWriter method is overridden in the MyPage class, which is derived from Page, so that MyHtmlTextWriter renders ASP.NET server controls when the page is requested. Si noti che questo esempio impedisce il TextWriter comportamento dell'adapter.Note that this example will prevent adapter TextWriter behavior.

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

Commenti

Il CreateHtmlTextWriter metodo crea un TextWriter oggetto tramite la Browser proprietà dell' Request oggetto associato alla richiesta di pagina.The CreateHtmlTextWriter method creates a TextWriter through the Browser property of the Request object associated with the page request. È possibile aggiungere un riferimento a un oggetto HtmlTextWriter nella browserCaps sezione di configurazione.You can add a reference to an HtmlTextWriter in the browserCaps configuration section. Eseguire l'override del CreateHtmlTextWriter metodo per eseguire la ricerca personalizzata.Override the CreateHtmlTextWriter method to perform custom lookup.

Si applica a

Vedi anche