HtmlTextWriter.FilterAttributes Yöntem

Tanım

Sayfanın veya Web sunucusu denetiminin tüm özelliklerindeki tüm işaretleme ve stil özniteliklerini kaldırır.

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

Örnekler

Aşağıdaki kod örneği, yöntemini geçersiz kılan sınıfından HtmlTextWriter türetilmiş bir özel sınıfın FilterAttributes nasıl kullanılacağını gösterir. Çağrıldığında geçersiz kılma, FilterAttributes metin yazıcının herhangi bir <label> öğeyi mi yoksa öğeyi mi <a> işleyip işlemediğini denetler:

  • Bir <label> öğe işleniyorsa, yöntemi öğesinde bir FilterAttributes özniteliğin style işlenip işlenmediğini denetler ve işlenmezse bir style öznitelik oluşturur ve bunu olarak color: blueayarlar.

  • Bir <a> öğe işleniyorsa, yöntemi bir FilterAttributes özniteliğin href eklenip eklenmeyeceğini belirler ve eklenmemişse URL'ye hrefbir http://www.cohowinery.com ekler.

// 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

Açıklamalar

Öznitelikler bir işaretleme öğesinde FilterAttributes işlenmeden önce yöntemi çağrılır. Buna karşılık yöntemi, FilterAttributes işlenmek OnAttributeRender üzere her öznitelik ve stil için ve OnStyleAttributeRender yöntemlerini çağırır.

Şunlara uygulanır

Ayrıca bkz.