aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

RichTextbox example or sample in or how to insert or store richtextbox data into database and display richtextbox data from database in gridview using

May 7, 2011

Here I will explain how to use richtextbox and how we can save our richtextbox data in database and how we can retrieve and display saved richtextbox data into our application using

Today I am writing this post to explain about freely available richtextbox. Previously I worked on one social networking site for that we got requirement to use richtextbox at that time we search so many websites to use richtextbox but we didn’t find useful ones. Recently I came across one website and I found one free available richtextbox. We can validate and we can use richtextbox very easily and by using this richtextbox we can insert data in different formats like bold, italic and different color format texts and we can insert images also. To use free Richtextbox download available dll here FreeTextbox . After download dll from that site create one new website in visual studio and add FreeTextbox dll reference to newly created website after that design aspx page like this 

After that Design your aspx page like this 

<%@ Register Assembly="FreeTextBox" Namespace="FreeTextBoxControls" TagPrefix="FTB" %>
<html xmlns="">
<head runat="server">
<title>Richtextbox Sample</title>
<script type="text/javascript">
function validate() {
var doc = document.getElementById('FreeTextBox1');
if (doc.value.length == 0) {
alert('Please Enter data in Richtextbox');
return false;
<form id="form1" runat="server">
<FTB:FreeTextBox ID="FreeTextBox1" runat="server">
<td valign="top">
<asp:GridView runat="server" ID="gvdetails" AutoGenerateColumns="false">
<asp:TemplateField HeaderText="RichtextBoxData">
<asp:Label ID="lbltxt" runat="server" Text='<%#Bind("RichtextData") %>'/>
<asp:Button ID="btnSubmit" runat="server" OnClientClick="return validate()"
Text="Submit" onclick="btnSubmit_Click" /><br />
<asp:Label ID="lbltxt" runat="server"/>
After that run your application richtextbox appears like this 

Now our richtextbox is ready do you know how we can save richtextbox data into database and which datatype is used to save richtextbox data and do you know how to display richtextbox on our web page no problem we can implement it now.

To save richtextbox data we need to use datatype nvarchar(MAX) now Design table like this in your SQL Server database and give name as RichTextBoxData

Column Name
Data Type
Allow Nulls
Int(Set Identity=true)
After that add following namespaces in code behind

using System.Data;
using System.Data.SqlClient;
Now write the following code in code behind 

SqlConnection con = new SqlConnection("Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB");
protected void Page_Load(object sender, EventArgs e)
protected void BindGridview()
SqlCommand cmd = new SqlCommand("select RichTextData from RichTextBoxData", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
gvdetails.DataSource = ds;
protected void btnSubmit_Click(object sender, EventArgs e)
SqlCommand cmd = new SqlCommand("insert into RichTextBoxData(RichTextData) values(@Richtextbox)", con);
cmd.Parameters.AddWithValue("@Richtextbox", FreeTextBox1.Text);
FreeTextBox1.Text = "";

Download sample code attached

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Subhash Jakhar said...

Hi Suresh
i have problem wit tis cod at saving data with style in tbl

the Error is:-
A potentially dangerous Request.Form value was detected from the client (FreeTextBox1="sdsd").


Anonymous said...

You might want to add Server.HtmlEncode(freetextbox.Text) when saving to the database and Server.HtmlDecode() when retrieving. Otherwise a serious security problem exists.

Subhash, you have to set ValidateRequest="false" on the @Page line, that opens the door to security problems but you should be ok if you use HtmlEncode/Decode.

Anonymous said...

Thank u very much sir ..Ur Great..It helped me a lot..

Anonymous said...

A potentially dangerous Request.Form value was detected from the client (FreeTextBox1="sdsd").
this error is coming after giving ValidateRequest="false" in iis.
Could you please help in this

krishraja88 said...

thanks so lot dear. Its really so good and excellent. thanks again.
Raja chaturvedi

krishraja88 said...

please add with me at facebook

krishna chaturvedi gonda up

Suresh Dasari said...


check the below post to solve your problem

shekar said...

Hi Suresh,

Thank you very much for this article. It is simply good.

RAJA said...

ADODB.Recordset rs = new ADODB.Recordset();

SqlCommand cmd = new SqlCommand("select RichTextData from table1",con);
rs.Open("select RichTextData from table1",con,ADODB.CursorTypeEnum.adOpenKeyset,ADODB.LockTypeEnum.adLockPessimistic,1);

When run that above the error becomes
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
plz give solution for it......

RAJA said...

After enter the data that will store it in database.then how to edit the typed content?

RAJA said...

in your above exercise can you explain with vb coding instead of C#...

Anonymous said...

required validations not working either through jquery or through fieldvalidators.

All Interview Questions said...

Folks will you pls help me I'm doing windowsform in that we are using saving data of richtextbox field in ".Rtf" format and i'm adding dataset required field to ".Rdlc" and showing it in reportViewer but Rtf format data is not working it showing same as it saving..??

but i tried to do it in html I do modified one record in html when i'm showing its working but how to save data in Html for RTB field?? do you have any idea's...

Anonymous said...

Hi, i'm having problems with the formatting of the control on my site? Looks like it inherits from the site master css? Is there a way of setting it to ignore the css or defaulting to what it should look like? Thanks Rich

Anonymous said...

Different font colors in Text box

Hi all . I have a requirement to add details of a paragraph with its header. The color of the header is different from the paragraph. can any one tell me how to add different colors in a textbox

Anonymous said...

sir,,this code not working....

Jack said...

how to use fck editor in our web site insert data through fck editor or show data into fck editor

Anonymous said...

can u tel me how to use it in the wpf,c#

JD Pandey said...

What is the coading og Logout in aasp dot net using c#?

JD Pandey said...

How to create a rich tex in asp dot net using c#?

kapuc said...

i have problem with integrating...
Error message is:

Error 4 Unable to resolve type 'FreeTextBoxControls.FreeTextBox, FreeTextBox, Version=, Culture=neutral, PublicKeyToken=5962a4e684a48b87'

in file license.licx

Could you help me please?

kapuc said...

Sorry, problem solved:)

Anonymous said...

I have the same probles as @kapuc.

Error 1 Unable to resolve type 'FreeTextBoxControls.FreeTextBox, FreeTextBox, Version=, Culture=neutral, PublicKeyToken=5962a4e684a48b87'

in file licenses.licx

Need help!
How did you make it?

santosh said...

I am using FreeTextBox in my web application which is developed in 4.0.
I have button under the free textbox.Button is working fine when there is no text in FreeTextBox,but if we enter any text inside FreeTextBox,button is not working.

Whats wrong?

Josey said...

in the case of mvc how is doing

Anonymous said...

i have write ValidateRequest="false" in page directive but still i have problem with this code.
It shows the following error:-

A potentially dangerous Request.Form value was detected from the client (FreeTextBox1="<font face="Georgia"...").

Raja Mar said...

how to disalble right click and Copy,paste options in free text box?

Anonymous said...


Virendra Prajapati said...

Master Of

Praveen said...

Hi Evertone,

i need to retrive image and data stored in dattabase and display it in textbox not in gridview what to use for it can help me please ?
data is inserted using the freetextbox concept.
Thanks in advance.

Anonymous said...

How to retrieve freetextbox placed in gridview

Anonymous said...


suraj javarat said...

Hello Sir,
How to auto enter data in all fields when we search any particular entry from the list. When we type some characters in search field if its relevant data is available in database then its details should appear in all the available fields.

Help me out sir! thanks in advance!
do send me the code on my id:

Zwelithini Dladlama said...

I am using Microsoft Studio Pro V9 SP1 2008 always gives this error:
Server Error in '/WebRichText' Application.
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

My email is

Zwelithini Dladlama said...

Source Error:

Line 24: protected void BindGridview()
Line 25: {
Line 26: con.Open();
Line 27: SqlCommand cmd = new SqlCommand("select RichTextData from RichTextBoxData", con);
Line 28: SqlDataAdapter da = new SqlDataAdapter(cmd);

Source File: c:\Documents and Settings\xxxxxxx\My Documents\Visual Studio 2008\WebSites\Tutor\RichTextboxSample\RichTextboxSample\Default.aspx.cs Line: 26

Anonymous said...


anee said...

i just want how to insert image from local drive to rich text box.......

Anonymous said...

i just want how to insert image from local drive to rich text box.......

firoz said...


Houth Dara said...

dear sir;

I have Problem when I use tag
and use fonts color are error.

A potentially dangerous Request.Form value was detected from the client (MainContent_FreeTextBox2="sf<font color="#FF1493...").

Please tell me too....

Anonymous said...

Sir, I want a particular record from the database that we already inserted into database....please help me...

Sandeep Yadav said...

How to add text editor in windows form by
sandeep yadav

Vinod b said...

How Can I Implement With Jquery..

Anonymous said...

plz suggest me other free Editor bcoz this editor is conflict with my other Ajax control.

Atul Rawat said...


Vishal Sharma said...

Nice application .. You are genious.

ANIL BABU Mandla said...

Good example,
Hi suresh can you provide code for Downloading functionality as you provide in your article just like( Download sample code attached)

Rahul Sud said...

Really Good Post. Thanks

Sumit Gaikwad said...

Hi Suresh,

Thanks for really nice post.

But i have problem here :
I can enter the richtext into the database but how can we display the text as a label in rich text format.

Kindly help me ....

Sandeep Yadav said...

How to add text editor in windows form by

Deepak Kr. Ruhela said...

I have a problem:
error is:
A potentially dangerous Request.Form value was detected from the client (adminmaster_ftxtname="<font color="#000080...").

Ashish Shiwakoti said...

how do i use that downloaded dll i have to install it or where do i place it

please help

Parshuram Kharade said...

Hi,suresh if i am copy text from anywhere and on right click paste it i want on that paste validate that textbox for enter digit only

Anonymous said...

MVC 3.0 the FreeTextBoxControls showing disabled

Anonymous said...

I am saving the text as a html file, the text appears properly in html but the image doesn't get diplayed,
i.e because it get saved in temp folder of the system, I want to save it to my path.

Kusuma K said...

Hi Suresh, may i know why we are using the free rich text control when we have it is asp. ajaxcontroltoolkit

Anonymous said...

Hi suresh, this control is not working in ie 10 browser with document mode as standard.
plz reply

sayed farhan said...

Hi suresh really nice work..
is there any validation for maxlenght?
please suggest me something

sayed farhan said...

can any one suggest me how set max length of rich textbox?

Anonymous said...

I m getting a error
Error 1 Task failed because "LC.exe" was not found, or the correct Microsoft Windows SDK is not installed. The task is looking for "LC.exe" in the "bin" subdirectory beneath the location specified in the InstallationFolder value of the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v6.0A. You may be able to solve the problem by doing one of the following: 1) Install the Microsoft Windows SDK for Windows Server 2008 and .NET Framework 3.5. 2) Install Visual Studio 2008. 3) Manually set the above registry key to the correct location. 4) Pass the correct location into the "ToolPath" parameter of the task. RichTextBox

I am using project insted of website

hari webbyin said...

hello there, thanks for TB, how can I add more fonts, colors and other styles in it.

Rajeshwar Loka said...


I want to develop a form same as this, when i enter some text and submit text should be displayed in the same form above with same gap between each user text and date should be generated by default on the date user submits and when i receive it should display the date to user automatically. what are the best tools develop and code to be used and one more important thing is user/any one should be able to download the file as pdf file which he is submited please help.

Muhammad Raheel said...

i got the error Microsoft JScript runtime error: Permission denied how can i solve it

chandra sekhar said...

when using grid view when row command event occur freetextbox control is viewed but in mozilla and IE 10 is not any click events on grid view

firoz said...


in ie 11 it is not working........

Prince Rajput said...

Dear sir i have nothing change in your code and also use ValidateRequest="false" in aspx page but still unable to save html mark up in database

Error: A potentially dangerous Request.Form value was detected from the client (FreeTextBox1="<font color="#FF1493...").

Please Help me
Thanks your Reader Prince Rajput

Anonymous said...

Dear sir,

I worked your applications. This works good. I implement this editor in my project Email send module. Body of textbox having this editor control. I formatting styles using this editor and bold, color,etc in textbox control characters. when i send email to customer email id then email will be received with html tags. how to avoid it and how to send email with formatting styles of text?

Ganesh said...

Problem with license :(

Ganesh said...

Problem with license :(

karan shah said...

How to search in Databse from richtextdata pls help

karan shah said...

On Hyper Link I want session

Anonymous said...

Hi Suresh,

I have used this RichTextBox control. Its working fine in Firefox but when I run this application in IE then getting below error.

Unhandled exception at line 37, column 59140 in http://localhost:7208/327a9f19be0c4db498a58790d6fbd9cd/browserLink

0x800a139e - JavaScript runtime error: Syntax error, unrecognized expression: unsupported pseudo: p

Can you please let me know the solution if you have any idea.

Thank you,

Anonymous said...

If we are opening the design of freetextbox once i am unable to build the solution again that is the build is not getting succeeded

Subramanya Ks said...

Can we read the content with images in the word document and display in richtextbox in runtime?

Nisha Saurabh Relan said...

I have to create html thru Rich text box and save to database and how to save image from rich text box in database

Kommarala Balaji said...


any one can help me to add dll file to in my project..

Anonymous said...

Hi, I have used free text box user control in visual web part in visual studio 2013,when i build the solution i got error like:The specified task executable "LC.exe" could not be run. The filename or extension is too long.Then from some blogs they told to delete the file :licenses.licx while building solution,so i deleted the file.But when i run the solution again i got the error like: "Could not load file or assembly 'FreeTextBox' or one of its dependencies. The system cannot find the file specified. "

Give your Valuable Comments

Other Related Posts

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.