This documentation is archived and is not being maintained.

HtmlTextWriter.RenderBeforeContent Method

Writes any text or spacing before the content and after the opening tag of an HTML element.

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

Return Value

The text or spacing to write prior to the content of the HTML element. If not overridden, this method returns a null reference (Nothing in Visual Basic).

Example

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

[Visual Basic] 
' Override the RenderBeforeContent method to write
' a font element that applies red to the text in a Label element.
<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _ 
Protected Overrides Function RenderBeforeContent() As String
   ' Check to determine whether the element being rendered
   ' is a label element. If so, render the opening tag
   ' of the font element; otherwise, call the base method.
   If TagKey = HtmlTextWriterTag.Label Then
      Return "<font color=""red"">"
   Else
      Return MyBase.RenderBeforeContent()
   End If
End Function 'RenderBeforeContent


[C#] 
// Override the RenderBeforeContent method to write
// a font element that applies red to the text in a Label element.
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] 
protected override string RenderBeforeContent()
{
   // Check to determine whether the element being rendered
   // is a label element. If so, render the opening tag
   // of the font element; otherwise, call the base method.
   if(TagKey == HtmlTextWriterTag.Label)
   {
      return "<font color=\"red\">";
   }
   else
   {
      return base.RenderBeforeContent();
   }
}

[C++] 
// Override the RenderBeforeContent method to write
// a font element that applies red to the text in a Label element.
protected:
   [System::Security::Permissions::PermissionSet(System::Security::Permissions::SecurityAction::Demand, Name="FullTrust")] 
   String* RenderBeforeContent() {
// Check to determine whether the element being rendered
// is a label element. If so, render the opening tag
// of the font element; otherwise, call the base method.
if (TagKey == HtmlTextWriterTag::Label) {
   return S"<font color=\"red\">";
} else {
   return __super::RenderBeforeContent();
}
   }

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