This documentation is archived and is not being maintained.

HtmlTextWriter.OnTagRender Method

Determines whether the specified HTML element will be rendered to the requesting page.

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

Parameters

name
The HTML element to render.
key
The HtmlTextWriterTag enumeration value associated with the HTML element.

Return Value

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

Example

[Visual Basic] The following code example overrides the OnTagRender method. It checks whether an HTML <Font> element is being renderred; if so, it uses the IsAttributeDefined method to check whether a Size attribute is being rendered. If that method call returns false if uses the AddAttribute method to create a Size attribute and set its value to 20 point. It then returns true.

[Visual Basic] 
' If an HTML Font element is to be rendered, check if it contains
' a Size attribute. If it does not, add one and set its value to
' 20 points then return true.
Protected Overrides Function OnTagRender( _
   name As String, _
   key As HtmlTextWriterTag) _
As Boolean
  
   If key = HtmlTextWriterTag.Font Then
      If Not IsAttributeDefined(HtmlTextWriterAttribute.Size) Then
         AddAttribute(HtmlTextWriterAttribute.Size, "20pt")
         Return True
      End If
   End If
   ' If the element is not a Font element, use 
   ' the base functionality of the OnTagRenderMethod.
   Return MyBase.OnTagRender(name, key)
End Function 'OnTagRender

[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: