ChtmlTextWriter.WriteBreak Method ()


Writes a br element to the cHTML output stream.

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

Public Overrides Sub 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 
  ' class, named SimpleLabel.
  Public Class ChtmlSimpleLabelAdapter
       Inherits WebControlAdapter

    ' Create the Control property to access
    ' the properties and methods of the
    ' SimpleLabel class.
    Protected Shadows ReadOnly Property Control() As SimpleLabel
          Return CType(MyBase.Control, SimpleLabel)
       End Get
    End Property

    ' 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 Overrides Sub Render(ByVal writer As HtmlTextWriter)
          Dim w As ChtmlTextWriter = New ChtmlTextWriter(writer)
          Dim value As String = Control.Text

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

      End Sub
End Class

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

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

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

<script runat="server">

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

    Dim sl As SimpleLabel = New SimpleLabel()
    sl.ID = "SimpleLabel1"
    sl.Text = "SimpleLabel Text"

  End Sub


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

.NET Framework
Available since 2.0
Return to top