This documentation is archived and is not being maintained.

ChtmlTextWriter.WriteBreak Method

Writes a br element to the cHTML output stream.

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

public override void WriteBreak()

Use the WriteBreak method to insert a line break into a stream of cHMTL.

This section contains two code examples. The first code example demonstrates how to create a cHTML class and custom properties. The second code example demonstrates how to use a custom class on a Web page.

To use the custom ChtmlSimplelabelAdapter adapter, add the following code to either the appropriate machine-wide file in the subdirectory for the browser of the .NET Framework configuration directory or to a custom browser file in the App_Browsers directory under the Web application root.

   <adapter controlType="AspNet.Samples.SimpleLabel"
   adapterType="AspNet.Samples.ChtmlSimpleLabelAdapter" />

The following code example demonstrates how to create a cHTML adapter class named ChtmlSimpleLabelAdapter for a class named SimpleLabel. It creates a custom Control property that allows the ChtmlSimpleLabelAdapter class to access the members of the SimpleLabel class, and then overrides the Render method. In the override, the following things occur:

  • It creates a reference to a ChtmlTextWriter object, named w, which is derived from the HtmlTextWriter object that is passed as the writer parameter for the Render method.

  • It creates a string and sets it equal to the SimpleLabel.Text value.

  • It calls the EnterStyle method to apply the styles that are defined by the ControlStyle property of the label to the cHTML output stream.

  • It writes the Text property value to the stream and closes the style block by calling the ExitStyle method.

  • It calls the WriteBreak method to render a br element to the output stream after the text and styles render.

	// Create a custom CHTML Adapter for a 
	// SimpleLabel class.
	public class ChtmlSimpleLabelAdapter : WebControlAdapter
		// Create the Control property to access
		// the properties and methods of the
		// SimpleLabel class.
		protected SimpleLabel Control
				return (SimpleLabel)base.Control;

		// Override the Render method to render text
		// in CHTML with the style defined by the control
		// and a <br> element after the text and styles
		// have been written to the output stream. 
		protected override void Render(HtmlTextWriter writer)
			ChtmlTextWriter w = new ChtmlTextWriter(writer);
			string value = Control.Text;

			// Render the text of the control using
			// the control's style settings.

The following example demonstrates how to use the SimpleLabel class in a Web page.

<%@ Page Language="C#" %>
<%@ Import Namespace="AspNet.Samples" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<script runat="server">

  protected void Page_Load(object sender, EventArgs e)
    SimpleLabel sl = new SimpleLabel();
    sl.ID = "SimpleLabel1";
    sl.Text = "SimpleLabel Text";


<html xmlns="" >
<head runat="server">
    <title>CHtmlTextWriter Example</title>
    <form id="form1" runat="server" >
      <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>    

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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