Export (0) Print
Expand All

Html32TextWriter.RenderBeforeContent Method

Writes any tab spacing or font information that appears before the content that is contained in an HTML element.

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)

protected override string RenderBeforeContent()

Return Value

Type: System.String
The font information or spacing to write before rendering the content of the HTML element; otherwise, if there is no such information to render, null.

The following code example demonstrates how to override the RenderBeforeContent method. The code checks whether a th element is being rendered, and then uses the SupportsBold method to check whether the requesting device can display bold formatting. If the device supports bold formatting, the RenderBeforeContent method writes the opening tag of a b element. If the device does not support bold formatting, the RenderBeforeContent method writes the opening tag of a font element with a color attribute set to the hexadecimal value for red.

Next, each method checks whether an h4 element is being rendered, and then uses the SupportsItalic property to check whether the requesting device can display italic formatting. If the device supports italic formatting, the RenderBeforeContent method writes the opening tag of an i element. If the device does not support italic formatting, the RenderBeforeContent method writes the opening tag of a font element with a color attribute set to the hexadecimal value for navy blue.

This code example is part of a larger example provided for the Html32TextWriter class.

		// Override the RenderBeforeContent method to render 
		// styles before rendering the content of a <th> element. 
		protected override string RenderBeforeContent()
		{
			// Check the TagKey property. If its value is 
			// HtmlTextWriterTag.TH, check the value of the  
			// SupportsBold property. If true, return the 
			// opening tag of a <b> element; otherwise, render 
			// the opening tag of a <font> element with a color 
			// attribute set to the hexadecimal value for red. 
			if (TagKey == HtmlTextWriterTag.Th)
			{
				if (SupportsBold)
					return "<b>";
				else 
					return "<font color=\"FF0000\">";
			}

			// Check whether the element being rendered 
            // is an <H4> element. If it is, check the  
            // value of the SupportsItalic property. 
            // If true, render the opening tag of the <i> element 
            // prior to the <H4> element's content; otherwise,  
            // render the opening tag of a <font> element  
            // with a color attribute set to the hexadecimal 
            // value for navy blue. 
			if (TagKey == HtmlTextWriterTag.H4)
			{
				if (SupportsItalic)
					return "<i>";
				else 
					return "<font color=\"000080\">";
			}
			// Call the base method. 
			return base.RenderBeforeContent();
		}

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft