Getting Started: Rich Text Editor for ASP.NET Web Forms

Add a full WYSIWYG HTML editor to a Web Forms page in a few lines. This guide covers registering the control, reading the HTML the user typed on postback, and turning on server-side image upload.

1. Register the control

Add the register directive at the top of your .aspx page (or register it once in web.config under <pages><controls>). It points the RTE tag prefix at the RichTextEditor assembly.

<%@ Register TagPrefix="RTE" Namespace="RTE" Assembly="RichTextEditor" %>

2. Drop the editor onto the page

Place the server control inside your <form runat="server">. Give it an ID so you can read its value in code-behind. The optional ContentCss attribute styles the editable area to match your site.

<RTE:Editor runat="server" ID="Editor1" ContentCss="example.css" />

That is the whole integration for a basic editor — no client script to wire up by hand.

3. Read the HTML the user typed

After a postback, the editor's markup is available server-side through its Text property, exactly like a TextBox. Save it, validate it, or render it back out:

protected void Submit(object sender, EventArgs e)
{
    string html = Editor1.Text;        // the HTML the user authored
    // save html to your database, send it, etc.
    Literal1.Text = Server.HtmlEncode(html);
}

To pre-fill the editor (for an edit screen), set Editor1.Text on first load:

if (!IsPostBack)
    Editor1.Text = "<p>Edit me</p>";

4. Enable image upload

Handle the server-side UploadImage event to receive files the user drops or pastes into the editor. This is also where you can post-process an upload — for example, applying a watermark before the image is stored:

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    Editor1.UploadImage += Editor1_UploadImage;
}

void Editor1_UploadImage(object sender, UploadImageEventArgs args)
{
    // inspect or transform args before the file is saved
}

See the live watermark demo for a complete, working upload handler.

5. Next steps

Frequently asked questions

How do I get the HTML the user entered?
Read the editor's Text property in code-behind after a postback, for example string html = Editor1.Text;.

How do I set the initial content?
Assign Editor1.Text on first load inside if (!IsPostBack) { ... }.

How are image uploads handled?
Handle the server-side UploadImage event. You can inspect or transform each file before it is stored.

Is RichTextEditor free to use?
It is a commercial control. See the pricing and licensing page for the current plans.

On this page

  • 1. Register the control
  • 2. Drop the editor onto the page
  • 3. Read the HTML the user typed
  • 4. Enable image upload
  • 5. Next steps