This documentation is archived and is not being maintained.

HtmlTextWriter.RenderBeforeTag Method

Writes any text or tab spacing that occurs before the opening tag of an HTML element to the HtmlTextWriter output stream.

[Visual Basic]
Protected Overridable Function RenderBeforeTag() As String
[C#]
protected virtual string RenderBeforeTag();
[C++]
protected: virtual String* RenderBeforeTag();
[JScript]
protected function RenderBeforeTag() : String;

Return Value

The text or tab spacing to write to the output stream. If not overridden, this method returns a null reference (Nothing in Visual Basic).

Example

[Visual Basic, C#, C++] The following example overrides the RenderBeforeTag method to determine whether the custom MyHtmlTextWriter object is about to render an HTML <label> element. If so, RenderBeforeTag inserts the opening tag of an HTML <font> element immediately before the label. If it is not rendering a <label> element, the base functionality of the RenderBeforeTag method is used.

[Visual Basic] 
' Override the RenderBeforeTag method to add the 
' opening tag of a Font element before the 
' opening tag of any Label elements rendered by this 
' custom HtmlTextWriter. 
Protected Overrides Function RenderBeforeTag() As String
   ' Compare the TagName property value to the
   ' string label to determine whether the element to 
   ' be rendered is a Label. If it is a Label,
   ' the opening tag of the Font element, with a Color
   ' style attribute set to red, is added before
   ' the Label.
   If String.Compare(TagName, "label") = 0 Then
      Return "<font color=""red"">"
   ' If a Label is not being rendered, use 
   ' the base RenderBeforeTag method.
   Else
      Return MyBase.RenderBeforeTag()
   End If
End Function 'RenderBeforeTag


[C#] 
// Override the RenderBeforeTag method to add the 
// opening tag of a Font element before the 
// opening tag of any Label elements rendered by this 
// custom HtmlTextWriter. 
protected override string RenderBeforeTag()
{
   // Compare the TagName property value to the
   // string label to determine whether the element to 
   // be rendered is a Label. If it is a Label,
   // the opening tag of the Font element, with a Color
   // style attribute set to red, is added before
   // the Label.
   if(String.Compare(TagName, "label") == 0)
   {
      return "<font color=\"red\">";
   }
   // If a Label is not being rendered, use 
   // the base RenderBeforeTag method.
   else
   {
      return base.RenderBeforeTag();
   }
}

[C++] 
// Override the RenderBeforeTag method to add the
// opening tag of a Font element before the
// opening tag of any Label elements rendered by this
// custom HtmlTextWriter.
protected:
String* RenderBeforeTag() {
   // Compare the TagName property value to the
   // String* label to determine whether the element to
   // be rendered is a Label. If it is a Label,
   // the opening tag of the Font element, with a Color
   // style attribute set to red, is added before
   // the Label.
   if (String::Compare(TagName, S"label") == 0) {
      return S"<font color=\"red\">";
   }
   // If a Label is not being rendered, use
   // the base RenderBeforeTag method.
   else {
      return __super::RenderBeforeTag();
   }
}

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