HtmlTextWriter.FilterAttributes-Methode
Entfernt alle Markup- und Formatattribute aus allen Eigenschaften der Seite oder des Webserversteuerelements.
Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)
Syntax
'Declaration
Protected Overridable Sub FilterAttributes
'Usage
Me.FilterAttributes
protected virtual void FilterAttributes ()
protected:
virtual void FilterAttributes ()
protected void FilterAttributes ()
protected function FilterAttributes ()
Hinweise
Bevor Attribute für ein Markupelement gerendert werden, wird die FilterAttributes-Methode aufgerufen. Anschließend ruft die FilterAttributes-Methode die OnAttributeRender-Methode und die OnStyleAttributeRender-Methode für jedes zu rendernde Attribut und Format auf.
Beispiel
Im folgenden Codebeispiel wird die Verwendung einer benutzerdefinierten von der HtmlTextWriter-Klasse abgeleiteten Klasse veranschaulicht, die die FilterAttributes-Methode überschreibt. Beim Aufruf überprüft die FilterAttributes-Überschreibung, ob der Textwriter <label>-Elemente oder <a>-Elemente rendert.
Wenn ein <label>-Element gerendert wird, prüft die FilterAttributes-Methode, ob ein style-Attribut für das Element gerendert wird. Wenn dies nicht der Fall ist, wird ein style-Attribut erstellt und sein Wert auf color: blue festgelegt.
Wenn ein <a>-Element gerendert wird, bestimmt die FilterAttributes-Methode, ob ein href-Attribut enthalten ist, und fügt andernfalls ein href zum URL http://www.cohowinery.com hinzu.
' 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
Plattformen
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 unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
HtmlTextWriter-Klasse
HtmlTextWriter-Member
System.Web.UI-Namespace
TextWriter
OnAttributeRender
OnStyleAttributeRender