New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Getting and Setting Content Overview

Most development tasks with RadEditor involve getting and setting content.

Setting Content

Use the Content property to set or get text content, including HTML markup. You can set the Content directly inline within the tag:

<telerik:RadEditor RenderMode="Lightweight" ID="RadEditor1" runat="server">
    <Content>This content is set <b>directly</b> inline and includes HTML markup</Content>

In code-behind, set the Content property:

private void Page_Load(object sender, EventArgs e)
    if (!Page.IsPostBack)
        RadEditor1.Content = "<strong>Sample HTML Content Loaded via the Html property</strong>";
Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    If Not Page.IsPostBack Then
        RadEditor1.Content = "<strong>Sample HTML Content Loaded via the Html property</strong>"
    End If
End Sub

Getting Content

You can access RadEditor content through the following properties:

  • Content: Used to get or set RadEditor text content, including the XHTML markup.

  • Text: This read-only property gets the RadEditor text without the HTML markup.

<asp:Button ID="Button1" runat="server" Text="Send" OnClick="Button1_Click" />
<asp:TextBox ID="TextBox1" runat="server" TextMode="multiline"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server" TextMode="multiline"></asp:TextBox>
<telerik:RadEditor RenderMode="Lightweight" ID="RadEditor1" runat="server">
protected void Button1_Click(object sender, EventArgs e)
    TextBox1.Text = RadEditor1.Text;
    TextBox2.Text = RadEditor1.Content;
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    TextBox1.Text = RadEditor1.Text
    TextBox2.Text = RadEditor1.Content
End Sub

The Text property of RadEditor returns editor content as pure text. It does convert <BR/> tags into \n lines correctly - so, if the editor content is loaded in a textarea, it will display those new lines correctly.

However, if the content is loaded back into the editor, of course, there is a problem, because the "\n" symbols mean nothing in HTML and they will be simply ignored by the browser. So, to display content in several lines, use code similar to the following example:

RadEditor1.Content = dbContent.Replace("\n", "<br/>");

See Also

In this article