RadEditor for ASP.NET

Getting / Setting Content Send comments on this topic.
See Also
Getting / Setting Content > Getting / Setting Content

Glossary Item Box

 

A lot of your development tasks with Telerik RadEditor will include setting / getting the content within the editor and later manipulating it in some way.

First, we will deal with setting the editor content:

Setting Content

Telerik RadEditor provides the Html property to set content in its content area. This property gets or sets the text content of the RadEditor control including the HTML markup.

We will look at two ways to do this:

  • Setting the content in the Page_Load method

Check whether the page was posted back and (if yes) set the editor content.  

C# Copy Code
private void Page_Load(object sender, EventArgs e)
{
 
if (!Page.IsPostBack)
 {
      RadEditor1.Html =
"<strong>Load Some HTML Content</strong>";
 }
}
 
VB.NET Copy Code
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
  If Not Page.IsPostBack Then
     RadEditor1.Html = "<strong>Load Some HTML Content</strong>"
  End If
End Sub 'Page_Load

 

  • Inline Editor Tag

Telerik RadEditor offers the unique ability to save content directly in the ASPX or ASCX file between the editor's opening and closing  tags:

ASPX Copy Code
<rad:RadEditor ID="RadEditor1" runat="server">Set Content</rad:RadEditor>


Getting Content

You can get the content of Telerik RadEditor by using the following properties:

  • Html - this property gets or sets the text content of the RadEditor control including the HTML markup.
  • Text - this property gets the text content of the RadEditor control without the HTML markup (note that this property is Read-Only).
  • Xhtml - this property gets the text content of the RadEditor control including the XHTML markup (note that this property is Read-Only).

 These properties can be used in two ways as shown below:

  • by registering for the editor's SubmitClicked event.
  • by registering an event handler for an external button that will submit the page and set the editor content in the event handler of the button. 

     

Registering for the SubmitClicked event 

ASPX Copy Code
<rad:RadEditor ID="RadEditor1"  runat="server" OnSubmitClicked="RadEditor1_SubmitClicked"></rad:RadEditor>  
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

 
C# Copy Code
protected void RadEditor1_SubmitClicked(object sender, EventArgs e)
{
      
//you can obtain the editor content and set it to an external source (database, html file, Label server control, etc)
      
//by setting the Html, Text or Xhtml properties
      
Label1.Text = RadEditor1.Html;
}

VB.NET Copy Code
Protected Sub RadEditor1_SubmitClicked(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadEditor1.SubmitClicked
      'you can obtain the editor content and set it to an external source (database, html file, Label server control, etc)
      'by setting the Html, Text or Xhtml properties
      Label1.Text = RadEditor1.Html
End Sub

Registering an event handler

For example, we register an Event Handler for an external button that will postback the page, get the editor content and set it to a TextBox control. Remember to set the ShowSubmitCancelButtons property to false in order to hide the default Submit and Cancel buttons of the editor:

ASPX Copy Code
<rad:RadEditor ID="RadEditor1" runat="server" ShowSubmitCancelButtons="False"></rad:RadEditor>  
<asp:Button ID="Button1" runat="server" Text="Send" />
<
asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine"></asp:TextBox>
C# Copy Code
protected void Button1_Click(object sender, EventArgs e)
{
      TextBox1.Text = RadEditor1.Text;
}
VB.NET Copy Code
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
       TextBox1.Text = RadEditor1.Text
End Sub

See Also