HtmlTextWriter.FilterAttributes HtmlTextWriter.FilterAttributes HtmlTextWriter.FilterAttributes HtmlTextWriter.FilterAttributes Method

定義

ページまたは Web サーバー コントロールのすべてのプロパティで、すべてのマークアップとスタイル属性を削除します。Removes all the markup and style attributes on all properties of the page or Web server control.

protected:
 virtual void FilterAttributes();
protected virtual void FilterAttributes ();
abstract member FilterAttributes : unit -> unit
override this.FilterAttributes : unit -> unit
Protected Overridable Sub FilterAttributes ()

次のコード例は、 HtmlTextWriterクラスから派生したカスタムクラスを使用して、 FilterAttributesメソッドをオーバーライドする方法を示しています。The following code example shows how to use a custom class, derived from the HtmlTextWriter class, that overrides the FilterAttributes method. オーバーライドされるとFilterAttributes 、テキストライターが要素<label>または<a>要素をレンダリングするかどうかを確認します。When called, the FilterAttributes override checks whether the text writer renders any <label> or <a> elements:

  • style FilterAttributes color: blue style要素がレンダリングされている場合、メソッドは、属性が要素に表示されているかどうかを確認し、存在しない場合は属性を作成してに設定します。 <label>If a <label> element is being rendered, the FilterAttributes method checks whether a style attribute is rendered on the element and, if not, creates a style attribute and sets it to color: blue.

  • href FilterAttributes http://www.cohowinery.com href要素がレンダリングされている場合、メソッドは属性が含まれているかどうかを判断し、存在しない場合はを URL に追加します。 <a>If an <a> element is being rendered, the FilterAttributes method determines whether an href attribute is included and, if not, adds an href to the URL http://www.cohowinery.com.

// 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に、メソッドが呼び出されます。Before attributes are rendered on a markup element, the FilterAttributes method is called. さらに、メソッドFilterAttributesは、レンダリングOnAttributeRenderするOnStyleAttributeRender各属性とスタイルに対してメソッドおよびメソッドを呼び出します。In turn, the FilterAttributes method calls the OnAttributeRender and OnStyleAttributeRender methods for each attribute and style to render.

適用対象

こちらもご覧ください