Page.CreateHtmlTextWriter(TextWriter) Page.CreateHtmlTextWriter(TextWriter) Page.CreateHtmlTextWriter(TextWriter) Page.CreateHtmlTextWriter(TextWriter) Method

定義

ページの内容を表示する HtmlTextWriter オブジェクトを作成します。Creates an HtmlTextWriter object to render the page's content.

protected public:
 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 Friend Overridable Function CreateHtmlTextWriter (tw As TextWriter) As HtmlTextWriter

パラメーター

tw
TextWriter TextWriter TextWriter TextWriter

TextWriter を作成するために使用する HtmlTextWriterThe TextWriter used to create the HtmlTextWriter.

戻り値

次のコード例ではCreateHtmlTextWriter 、メソッドを使用して、とHtmlTextWriterいう名前MyHtmlTextWriterのカスタムオブジェクトのインスタンスを作成します。The following code example uses the CreateHtmlTextWriter method to create an instance of a custom HtmlTextWriter object named MyHtmlTextWriter. メソッドは、からMyPage Page派生したクラスでオーバーライドされるため、ページMyHtmlTextWriterが要求されたときに ASP.NET サーバーコントロールがレンダリングされます。 CreateHtmlTextWriterThe 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. この例では、アダプター TextWriterの動作が禁止されていることに注意してください。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
Imports System.IO
Imports System.Web.UI

Namespace WebPage

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

      <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 'Render
   End Class 'MyPage
	

   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 'New
   End Class 'MyHtmlTextWriter
End Namespace 'WebPage

注釈

メソッドCreateHtmlTextWriterは、ページ要求にBrowser関連付けらRequestれているオブジェクトのプロパティを使用して、をTextWriter作成します。The CreateHtmlTextWriter method creates a TextWriter through the Browser property of the Request object associated with the page request. 構成browserCapsセクションで、 HtmlTextWriterへの参照を追加できます。You can add a reference to an HtmlTextWriter in the browserCaps configuration section. カスタム検索CreateHtmlTextWriterを実行するには、メソッドをオーバーライドします。Override the CreateHtmlTextWriter method to perform custom lookup.

適用対象

こちらもご覧ください