HtmlTextWriter.FilterAttributes メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
ページまたは Web サーバー コントロールのすべてのプロパティのすべてのマークアップ属性とスタイル属性を削除します。
protected:
virtual void FilterAttributes();
protected virtual void FilterAttributes();
abstract member FilterAttributes : unit -> unit
override this.FilterAttributes : unit -> unit
Protected Overridable Sub FilterAttributes ()
例
次のコード例は、HtmlTextWriter メソッドをオーバーライドする、FilterAttributes クラスから派生したカスタム クラスを使用する方法を示しています。
FilterAttributesオーバーライドを呼び出すと、テキスト ライターが<label>要素または<a>要素をレンダリングするかどうかを確認します。
<label>要素がレンダリングされている場合、FilterAttributes メソッドはstyle属性が要素にレンダリングされているかどうかをチェックし、表示されない場合は、style属性を作成してcolor: blueに設定します。<a>要素がレンダリングされている場合、FilterAttributes メソッドはhref属性を含めるかどうかを判断し、含まれていない場合は URL http://www.cohowinery.comにhrefを追加します。
// Override the FilterAttributes method to check whether
// <label> and <anchor> elements contain specific attributes.
virtual void FilterAttributes() override
{
// If the <label> element is rendered and a style
// attribute is not defined, add a style attribute
// and set its value to blue.
if ( TagKey == HtmlTextWriterTag::Label )
{
if ( !IsAttributeDefined( HtmlTextWriterAttribute::Style ) )
{
AddAttribute( "style", EncodeAttributeValue( "color:blue", true ) );
Write( NewLine );
Indent = 3;
OutputTabs();
}
}
// If an <anchor> element is rendered and an href
// attribute has not been defined, call the AddAttribute
// method to add an href attribute
// and set it to http://www.cohowinery.com.
// Use the EncodeUrl method to convert any spaces to %20.
if ( TagKey == HtmlTextWriterTag::A )
{
if ( !IsAttributeDefined( HtmlTextWriterAttribute::Href ) )
{
AddAttribute( "href", EncodeUrl( "http://www.cohowinery.com" ) );
}
}
// Call the FilterAttributes method of the base class.
__super::FilterAttributes();
}
// Override the FilterAttributes method to check whether
// <label> and <anchor> elements contain specific attributes.
protected override void FilterAttributes()
{
// If the <label> element is rendered and a style
// attribute is not defined, add a style attribute
// and set its value to blue.
if (TagKey == HtmlTextWriterTag.Label)
{
if (!IsAttributeDefined(HtmlTextWriterAttribute.Style))
{
AddAttribute("style", EncodeAttributeValue("color:blue", true));
Write(NewLine);
Indent = 3;
OutputTabs();
}
}
// If an <anchor> element is rendered and an href
// attribute has not been defined, call the AddAttribute
// method to add an href attribute
// and set it to http://www.cohowinery.com.
// Use the EncodeUrl method to convert any spaces to %20.
if (TagKey == HtmlTextWriterTag.A)
{
if (!IsAttributeDefined(HtmlTextWriterAttribute.Href))
{
AddAttribute("href", EncodeUrl("http://www.cohowinery.com"));
}
}
// Call the FilterAttributes method of the base class.
base.FilterAttributes();
}
' Override the FilterAttributes method to check whether
' <label> and <anchor> elements contain specific attributes.
Protected Overrides Sub FilterAttributes()
' If the <label> element is rendered and a style
' attribute is not defined, add a style attribute
' and set its value to blue.
If TagKey = HtmlTextWriterTag.Label Then
If Not IsAttributeDefined(HtmlTextWriterAttribute.Style) Then
AddAttribute("style", EncodeAttributeValue("color:blue", True))
Write(NewLine)
Indent = 3
OutputTabs()
End If
End If
' If an <anchor> element is rendered and an href
' attribute has not been defined, call the AddAttribute
' method to add an href attribute
' and set it to http://www.cohowinery.com.
' Use the EncodeUrl method to convert any spaces to %20.
If TagKey = HtmlTextWriterTag.A Then
If Not IsAttributeDefined(HtmlTextWriterAttribute.Href) Then
AddAttribute("href", EncodeUrl("http://www.cohowinery.com"))
End If
End If
' Call the FilterAttributes method of the base class.
MyBase.FilterAttributes()
End Sub
注釈
マークアップ要素に属性をレンダリングする前に、 FilterAttributes メソッドが呼び出されます。 さらに、 FilterAttributes メソッドは、レンダリングする各属性とスタイルの OnAttributeRender メソッドと OnStyleAttributeRender メソッドを呼び出します。