This documentation is archived and is not being maintained.

HtmlTextWriter.OnStyleAttributeRender Method

Determines whether the specified HTML style attribute and its value will be rendered to the requesting page.

[Visual Basic]
Protected Overridable Function OnStyleAttributeRender( _
   ByVal name As String, _
   ByVal value As String, _
   ByVal key As HtmlTextWriterStyle _
) As Boolean
[C#]
protected virtual bool OnStyleAttributeRender(
 string name,
 string value,
 HtmlTextWriterStyle key
);
[C++]
protected: virtual bool OnStyleAttributeRender(
 String* name,
 String* value,
 HtmlTextWriterStyle key
);
[JScript]
protected function OnStyleAttributeRender(
   name : String,
 value : String,
 key : HtmlTextWriterStyle
) : Boolean;

Parameters

name
The HTML style attribute to render.
value
The value that is assinged to the HTML style attribute.
key
The HtmlTextWriterStyle enumeration value associated with the HTML style attribute.

Return Value

true if the HTML style 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 a style from being rendered.

Example

[Visual Basic] The following code example overrides the OnStyleAttributeRender method. The code checks whether a Color attribute is rendered. If so, it checks whether the value of the attribute is purple. If not, it uses the AddStyleAttribute to set it to purple and returns false.

[Visual Basic] 
' If an HTML Color style attribute is to be rendered, 
' compare its value to purple. If it is not purple, add the
' style attribute and set the value to purple,
' then return false.
Protected Overrides Function OnStyleAttributeRender(name As String, _
  value As String, _
  key As HtmlTextWriterStyle) _
As Boolean
      
   If key = HtmlTextWriterStyle.Color Then 
      If [String].Compare(value, "purple") <> 0 Then
         AddStyleAttribute("color", "purple")
         Return False
      End If
   End If

   ' If the style attribute in not a Color attribute,
   ' use the base functionality of the
   ' OnStyleAttributeRender method.         
   Return MyBase.OnStyleAttributeRender(name, value, key)
End Function 'OnStyleAttributeRender

[C#, C++, JScript] No example is available for C#, C++, or JScript. To view a Visual Basic example, click the Language Filter button Language Filter 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

Show: