次の方法で共有


HtmlTextWriter.OnTagRender メソッド

指定した HTML 要素を要求側のページに表示するかどうかを決定します。

Protected Overridable Function OnTagRender( _
   ByVal name As String, _   ByVal key As HtmlTextWriterTag _) As Boolean
[C#]
protected virtual bool OnTagRender(stringname,HtmlTextWriterTagkey);
[C++]
protected: virtual bool OnTagRender(String* name,HtmlTextWriterTagkey);
[JScript]
protected function OnTagRender(
   name : String,key : HtmlTextWriterTag) : Boolean;

パラメータ

  • name
    表示する HTML 要素。
  • key
    HTML 要素に関連付けられた HtmlTextWriterTag 列挙値。

戻り値

HTML 要素をページに表示する場合は true 。それ以外の場合は false

解説

HtmlTextWriter から継承する場合は、このメソッドをオーバーライドして false を返し、HTML 要素を表示しないようにできます。

使用例

[Visual Basic] OnTagRender メソッドをオーバーライドするコード例を次に示します。このコードは、HTML の <Font> 要素が表示に適用されるかどうかをチェックし、そうであれば、IsAttributeDefined メソッドを使用して、Size 属性が表示に適用されるかどうかをチェックします。その戻り値が false であれば、AddAttribute メソッドを使用して Size 属性を作成し、その値を 20 ポイントに設定します。その後、 true を返します。

 
' If an HTML Font element is to be rendered, check if it contains
' a Size attribute. If it does not, add one and set its value to
' 20 points then return true.
Protected Overrides Function OnTagRender( _
   name As String, _
   key As HtmlTextWriterTag) _
As Boolean
  
   If key = HtmlTextWriterTag.Font Then
      If Not IsAttributeDefined(HtmlTextWriterAttribute.Size) Then
         AddAttribute(HtmlTextWriterAttribute.Size, "20pt")
         Return True
      End If
   End If
   ' If the element is not a Font element, use 
   ' the base functionality of the OnTagRenderMethod.
   Return MyBase.OnTagRender(name, key)
End Function 'OnTagRender

[C#, C++, JScript] C#、C++、および JScript のサンプルはありません。Visual Basic のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ

参照

HtmlTextWriter クラス | HtmlTextWriter メンバ | System.Web.UI 名前空間