次の方法で共有


HtmlTextWriter.OnAttributeRender メソッド

指定したマークアップ属性とその値を現在のマークアップ要素に出力するかどうかを決定します。

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)

構文

'宣言
Protected Overridable Function OnAttributeRender ( _
    name As String, _
    value As String, _
    key As HtmlTextWriterAttribute _
) As Boolean
'使用
Dim name As String
Dim value As String
Dim key As HtmlTextWriterAttribute
Dim returnValue As Boolean

returnValue = Me.OnAttributeRender(name, value, key)
protected virtual bool OnAttributeRender (
    string name,
    string value,
    HtmlTextWriterAttribute key
)
protected:
virtual bool OnAttributeRender (
    String^ name, 
    String^ value, 
    HtmlTextWriterAttribute key
)
protected boolean OnAttributeRender (
    String name, 
    String value, 
    HtmlTextWriterAttribute key
)
protected function OnAttributeRender (
    name : String, 
    value : String, 
    key : HtmlTextWriterAttribute
) : boolean
適用できません。

パラメータ

  • name
    出力する属性の名前を格納している文字列。
  • value
    属性に割り当てる値を格納している文字列。

戻り値

常に true

解説

HtmlTextWriter クラスで実装されている OnAttributeRender メソッドは、常に true を返します。OnAttributeRender のオーバーライドで、ページに属性を出力するかどうかを決定できます。

継承元へのメモ : HtmlTextWriter クラスから継承する場合は、OnAttributeRender メソッドをオーバーライドして false を返し、属性をまったく出力しない、特定の要素に出力しない、または特定のマークアップでは出力しないようにできます。たとえば、HtmlTextWriter から派生したオブジェクトが bgcolor 属性を <table> 要素に出力しないようにするには、OnAttributeRender をオーバーライドして、name から bgcolor が渡され、TagName プロパティ値が table のときに false を返すようにできます。

使用例

OnAttributeRender メソッドをオーバーライドする方法を次のコード例に示します。Size 属性が出力されても、Size 値が 30pt ではない場合、OnAttributeRender オーバーライドは AddAttribute メソッドを呼び出し、Size 属性を追加して、その値を 30pt に設定します。

' If a size attribute is to be rendered, compare its value to 30 point.
' If it is not set to 30 point, add the attribute and set the value to 30
' then return false.
Protected Overrides Function OnAttributeRender(name As String, _
    value As String, _
    key As HtmlTextWriterAttribute) _
As Boolean

    If key = HtmlTextWriterAttribute.Size Then
        If [String].Compare(value, "30pt") <> 0 Then
            AddAttribute("size", "30pt")
            Return False
        End If
    End If

    ' If the attribute is not a size attribute, use
    ' the base functionality of the OnAttributeRender method.
    Return MyBase.OnAttributeRender(name, value, key)
End Function 'OnAttributeRender
// If a size attribute is to be rendered, compare its value to 30 point.
// If it is not set to 30 point, add the attribute and set the value to 30,
// then return false.
protected override bool OnAttributeRender(string name,
    string value,
    HtmlTextWriterAttribute key)
{

    if (key == HtmlTextWriterAttribute.Size)
    {
        if (string.Compare(value, "30pt") != 0)
        {
            AddAttribute("size", "30pt");
            return false;
        }
    }

    // If the attribute is not a size attribute, use
    // the base functionality of the OnAttributeRender method.
    return base.OnAttributeRender(name, value, key);
}

プラットフォーム

Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

バージョン情報

.NET Framework

サポート対象 : 3.0,2.0,1.1,1.0

参照

関連項目

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