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
<Content> tag:
| [ASP.NET] Setting Content Inline |
Copy Code |
|
<telerik:RadEditor ID="RadEditor1" runat="server">
<Content>This content is
set <b>directly</b> inline and includes HTML markup</Content>
</telerik:RadEditor>
|
In code-behind, set the Content property:
| [C#] Setting Content in Code-Behind |
Copy Code |
|
private void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
RadEditor1.Content = "<strong>Sample HTML Content Loaded via the Html
property</strong>";
}
}
|
| [VB] Setting Content in Code-Behind |
Copy Code |
|
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.NET] RadEditor Declaration |
Copy Code |
|
<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 ID="RadEditor1" runat="server">
</telerik:RadEditor>
|
| [C#] Retrieving Text and Text with HTML |
Copy Code |
|
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = RadEditor1.Text;
TextBox2.Text = RadEditor1.Content;
}
|
| [VB] Retrieving Text and Text with HTML |
Copy Code |
|
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
TextBox1.Text = RadEditor1.Text
TextBox2.Text = RadEditor1.Content
End Sub
|
Note:
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 such as
RadEditor1.Content = dbContent.Replace("\n", "<br/>");
See Also