HtmlTextWriter.OnAttributeRender Method
Determines whether the specified HTML attribute and its value will be rendered to the requesting page.
[Visual Basic] Protected Overridable Function OnAttributeRender( _ ByVal name As String, _ ByVal value As String, _ ByVal key As HtmlTextWriterAttribute _ ) As Boolean [C#] protected virtual bool OnAttributeRender( string name, string value, HtmlTextWriterAttribute key ); [C++] protected: virtual bool OnAttributeRender( String* name, String* value, HtmlTextWriterAttribute key ); [JScript] protected function OnAttributeRender( name : String, value : String, key : HtmlTextWriterAttribute ) : Boolean;
Parameters
- name
- The HTML attribute to render.
- value
- The value that is assinged to the HTML attribute.
- key
- The HtmlTextWriterAttribute enumeration value associated with the HTML attribute.
Return Value
true if the attribute will be rendered to the page; otherwise, false.
Remarks
If you inherit from HtmlTextWriter, you can override this method to return false to prevent an attribute from being rendered.
Example
[Visual Basic] The following code example overrides the OnAttributeRender method. If an HMTL Size attribute is rendered, but its value does not equal 30 point, this method calls the AddAttribute method to add a size attribute and set its value to 30 point.
[Visual Basic]
' If an HTML Size attribute is to be rendered, compare its value to 30
' If it is not set to 30 points, add the attribute and set the value to 30
' then return false.
Protected Overrides Function OnAttributeRender(name As String, _
value As String, _
key As HtmlTextWriterAttribute) _
As Boolean
If key = HtmlTextWriterAttribute.Size Then
If [String].Compare(value, "30pt") <> 0 Then
AddAttribute("size", "30pt")
Return False
End If
End If
' If the attribute in not a Size attribute, use
' the base functionality of the OnAttributeRender method.
Return MyBase.OnAttributeRender(name, value, key)
End Function 'OnAttributeRender
[C#, C++, JScript] No example is available for C#, C++, or JScript. To view a Visual Basic example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
See Also
HtmlTextWriter Class | HtmlTextWriter Members | System.Web.UI Namespace