Click here to Skip to main content
15,889,116 members
Articles / Web Development / ASP.NET
Tip/Trick

Rich Text Editor with ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.00/5 (13 votes)
11 Sep 2012CPOL2 min read 216.2K   13.3K   24   36
How to implement free RichText editor into ASP.NET website

Introduction

As we know, ASP.NET lacks a control that we need most, RichText editor.

If you are trying to create an application or website with Admin Panel or Blog or Forum Website or some such project for Web in ASP.NET platform, we need RichText Editor.

To overcome this, we can use many open source JavaScript based editors, like Tiny MCE, FCKEditor, etc.

Content

In this tip, we would learn how to Implement Free RichText Editor into ASP.NET website. We are using TinyMCE editor here.

We are using TinyMCE, which is one of the most popular and Open Source projects. Download the latest version of TinyMCE from download page, and extract the zip file.

Image 1

Browse the extracted location and go to ..\tinymce_3.5.6\tinymce\jscripts folder.

Now copy the tinymce folder from the above location to your solution in Visual Studio.

Image 2

Add a page where you want to implement RichTextbox and design the Page.

Image 3

Now let's move to the topic on how to add TinyMCE in Page and Richtext box control placed for Content of Blog in the above sample.

Insert JavaScript file tiny_mce.js in Web Page and also initialize this function.

Place this code into head section:

HTML
  <script type="text/javascript" 
src="tiny_mce/tiny_mce.js"></script>
    <script type="text/javascript" language="javascript">
        tinyMCE.init({
            // General options
            mode: "textareas",
            theme: "advanced",
            plugins: "pagebreak,style,layer,table,save,
            advhr,advimage,advlink,emotions,iespell,inlinepopups",
           
        });
    </script>

Note: You can have so many settings, look in Samples and Help Doc of TinyMCE.

Now run the Page. Look how it looked.

Image 4

Without any additional practice, our TextBox with Multiline turned into RichText Editor.

Now, it's ok as per Requirement. No, when you will send Command to Server, it will return Error like below:

Image 5

We have to add just one line of code in Web.config file and one property in Default.aspx form (Page with Rich Text Editor).

That is:

In web.config:

HTML
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
    <httpRuntime requestValidationMode="2.0"/>
  </system.web>
</configuration>

and in Page directive:

C#
ValidateRequest = "false"
ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" 
CodeFile="Default.aspx.cs" Inherits="_Default" ValidateRequest="false" %> 

Now, you can save the data in database, do postback, retrieve same in Rich Text box and do anything you want.

Conclusion

IT is Jugad. So anything is possible here. Don't worry about things that are not available. Just modify and make use of things that are available. Tiny MCE is one of the most well known and popular Rich Text editors (WYSIWYG).

Reference

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Founder P.Yar.B Complex
Nepal Nepal
John Bhatt is an IT Professional having interest in Web technology. He is Web Designer, Developer, Software Developer, Blogger and Technology Geek. Currently he writes his Blogs at Blog of P.Yar.B and various other Sites. He is Main author and founder of Download Center.
Contact Him at : Facebook | Twitter | Website | PRB - Blog.

Comments and Discussions

 
QuestionHelp doc Pin
Amalraj Ramesh12-Feb-13 1:43
Amalraj Ramesh12-Feb-13 1:43 
AnswerRe: Help doc Pin
John Bhatt23-Jan-14 5:09
professionalJohn Bhatt23-Jan-14 5:09 
GeneralMy vote of 4 Pin
Maddy selva24-Oct-12 19:42
professionalMaddy selva24-Oct-12 19:42 
GeneralRe: My vote of 4 Pin
John Bhatt25-Oct-12 3:44
professionalJohn Bhatt25-Oct-12 3:44 
GeneralThanks! Pin
Maddy selva27-Oct-12 2:11
professionalMaddy selva27-Oct-12 2:11 
GeneralRe: Thanks! Pin
John Bhatt27-Oct-12 2:18
professionalJohn Bhatt27-Oct-12 2:18 
QuestionHow do you validate against attacks? Pin
Philippe Mori11-Sep-12 10:13
Philippe Mori11-Sep-12 10:13 
AnswerRe: How do you validate against attacks? Pin
John Bhatt11-Sep-12 19:11
professionalJohn Bhatt11-Sep-12 19:11 
Generalthanks Pin
Sirwan Afifi11-Sep-12 10:10
Sirwan Afifi11-Sep-12 10:10 
GeneralRe: thanks Pin
John Bhatt26-Sep-12 22:16
professionalJohn Bhatt26-Sep-12 22:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.