指定されたマークアップ スタイル属性とその値を現在のマークアップ要素に出力するかどうかを決定します。
名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)
構文
'宣言
Protected Overridable Function OnStyleAttributeRender ( _
name As String, _
value As String, _
key As HtmlTextWriterStyle _
) As Boolean
'使用
Dim name As String
Dim value As String
Dim key As HtmlTextWriterStyle
Dim returnValue As Boolean
returnValue = Me.OnStyleAttributeRender(name, value, key)
protected virtual bool OnStyleAttributeRender (
string name,
string value,
HtmlTextWriterStyle key
)
protected:
virtual bool OnStyleAttributeRender (
String^ name,
String^ value,
HtmlTextWriterStyle key
)
protected boolean OnStyleAttributeRender (
String name,
String value,
HtmlTextWriterStyle key
)
protected function OnStyleAttributeRender (
name : String,
value : String,
key : HtmlTextWriterStyle
) : boolean
適用できません。
パラメータ
- name
出力するスタイル属性の名前を格納している文字列。
- value
スタイル属性に割り当てる値を格納している文字列。
- key
スタイル属性に関連付けられている HtmlTextWriterStyle。
戻り値
常に true。
解説
HtmlTextWriter クラスで実装されている OnStyleAttributeRender メソッドは、常に true を返します。OnStyleAttributeRender オーバーライドで、ページにスタイル属性を出力するかどうかを確認できます。
継承元へのメモ : HtmlTextWriter クラスから継承する場合は、OnStyleAttributeRender メソッドをオーバーライドして false を返し、スタイル属性をまったく出力しない、特定の要素に出力しない、または特定のマークアップでは出力しないようにできます。たとえば、HtmlTextWriter から派生したオブジェクトが color 属性を <p> 要素に出力しないようにするには、OnStyleAttributeRender をオーバーライドして、name から color が渡され、TagName プロパティ値が p のときに false を返すようにできます。
使用例
OnStyleAttributeRender メソッドをオーバーライドする方法を次のコード例に示します。Color スタイル属性が出力されても、Color 値が purple ではない場合、OnStyleAttributeRender オーバーライドは AddStyleAttribute メソッドを使用し、Color 属性を purple に設定します。
' If a color style attribute is to be rendered,
' compare its value to purple. If it is not set to
' purple, add the style attribute and set the value
' to purple, then return false.
Protected Overrides Function OnStyleAttributeRender(name As String, _
value As String, _
key As HtmlTextWriterStyle) _
As Boolean
If key = HtmlTextWriterStyle.Color Then
If [String].Compare(value, "purple") <> 0 Then
AddStyleAttribute("color", "purple")
Return False
End If
End If
' If the style attribute is not a color attribute,
' use the base functionality of the
' OnStyleAttributeRender method.
Return MyBase.OnStyleAttributeRender(name, value, key)
End Function 'OnStyleAttributeRender
// If a color style attribute is to be rendered,
// compare its value to purple. If it is not set to
// purple, add the style attribute and set the value
// to purple, then return false.
protected override bool OnStyleAttributeRender(string name,
string value,
HtmlTextWriterStyle key)
{
if (key == HtmlTextWriterStyle.Color)
{
if (string.Compare(value, "purple") != 0)
{
AddStyleAttribute("color", "purple");
return false;
}
}
// If the style attribute is not a color attribute,
// use the base functionality of the
// OnStyleAttributeRender method.
return base.OnStyleAttributeRender(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
HtmlTextWriterStyle