Export (0) Print
Expand All

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 ()
public void WriteBreak ()
public override function WriteBreak ()
Not applicable.

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.

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

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
    {
        get
        {
            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.
        w.EnterStyle(Control.ControlStyle);
        w.Write(value);
        w.ExitStyle(Control.ControlStyle);
        w.WriteBreak();
    }
}

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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

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

  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>CHtmlTextWriter Example</title>
</head>
<body>
    <form id="form1" runat="server" >
    <div>
      <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>    
    </div>
    </form>
</body>
</html>

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft