HtmlTextWriter.FilterAttributes メソッド
アセンブリ: System.Web (system.web.dll 内)


属性がマークアップ要素に出力される前に、FilterAttributes メソッドが呼び出されます。次に、FilterAttributes メソッドは、出力する各属性およびスタイルについて、OnAttributeRender メソッドと OnStyleAttributeRender メソッドを呼び出します。

FilterAttributes メソッドをオーバーライドする HtmlTextWriter クラスから派生したカスタム クラスを使用する方法を次のコード例に示します。FilterAttributes オーバーライドが呼び出されると、<label> 要素または <a> 要素をテキスト ライタが出力しているかどうかがチェックされます。
-
出力する要素が <label> の場合、FilterAttributes メソッドが、この要素に style 属性があるかどうかをチェックし、ない場合は、style 属性を作成して、color: blue を設定しています。
-
出力する要素が <a> の場合、FilterAttributes メソッドは、href 属性が含まれているかどうかをチェックし、含まれていない場合は、http://www.cohowinery.com という URL に href を追加します。
' 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
// 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. 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 void FilterAttributes() { // If the Label tag is being rendered and a style // attribute is not defined, add a style attribute // and set its value to blue. if (get_TagKey().Equals(HtmlTextWriterTag.Label)) { if (!(IsAttributeDefined(HtmlTextWriterAttribute.Style))) { AddAttribute("style", EncodeAttributeValue("color:blue" , true)); Write(get_NewLine()); set_Indent(3); OutputTabs(); } } // If an Anchor element is being 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 (get_TagKey().Equals(HtmlTextWriterTag.A)) { if (!(IsAttributeDefined(HtmlTextWriterAttribute.Href))) { AddAttribute("href", EncodeUrl("http://www.cohowinery.com")); } } // Call the FilterAttributes method of the base class. super.FilterAttributes(); } //FilterAttributes

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


HtmlTextWriter クラス
HtmlTextWriter メンバ
System.Web.UI 名前空間
TextWriter
OnAttributeRender
OnStyleAttributeRender
Weblioに収録されているすべての辞書からHtmlTextWriter.FilterAttributes メソッドを検索する場合は、下記のリンクをクリックしてください。

- HtmlTextWriter.FilterAttributes メソッドのページへのリンク