Aspdotnet-Suresh

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

Introduction

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 asp.net.

Description:
  
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="http://www.w3.org/1999/xhtml">
<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;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
<FTB:FreeTextBox ID="FreeTextBox1" runat="server">
</FTB:FreeTextBox>
</td>
<td valign="top">
<asp:GridView runat="server" ID="gvdetails" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="RichtextBoxData">
<ItemTemplate>
<asp:Label ID="lbltxt" runat="server" Text='<%#Bind("RichtextData") %>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</div>
<asp:Button ID="btnSubmit" runat="server" OnClientClick="return validate()"
Text="Submit" onclick="btnSubmit_Click" /><br />
<asp:Label ID="lbltxt" runat="server"/>
</form>
</body>
</html>
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
Id
Int(Set Identity=true)
No
RichTextData
nvarchar(MAX)
Yes
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)
{
if(!IsPostBack)
{
BindGridview();
}
}
protected void BindGridview()
{
con.Open();
SqlCommand cmd = new SqlCommand("select RichTextData from RichTextBoxData", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
gvdetails.DataSource = ds;
gvdetails.DataBind();
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("insert into RichTextBoxData(RichTextData) values(@Richtextbox)", con);
cmd.Parameters.AddWithValue("@Richtextbox", FreeTextBox1.Text);
cmd.ExecuteNonQuery();
con.Close();
FreeTextBox1.Text = "";
BindGridview();
}
Demo


Download sample code attached

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

Get the latest Asp.net, C#.net, 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

65 comments :

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").

TNX

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
Email-krishraja88@gmail.com

krishraja88 said...

please add with me at facebook

krishna chaturvedi gonda up
or
send
invitation at-krishnachaturvedimca@gmail.com

Suresh Dasari said...

@subhash

check the below post to solve your problem
http://www.aspdotnet-suresh.com/2011/12/potentially-dangerous-requestform-value.html

shekar said...

Hi Suresh,

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

RAJA said...

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


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...
Thanks
Pruthvi

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...

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

Error 4 Unable to resolve type 'FreeTextBoxControls.FreeTextBox, FreeTextBox, Version=3.3.1.12354, 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=3.3.1.12354, Culture=neutral, PublicKeyToken=5962a4e684a48b87'

in file licenses.licx

Need help!
How did you make it?

santosh said...

Hi,
I am using FreeTextBox in my web application which is developed in asp.net 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...

Hi,
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...

gkhghghghg
gjghjhjh
kjbjhbjhjh
jhjhjhjhhjhjh
456789076543245678

Virendra Prajapati said...

Master Of asp.net

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...

ccccccccc

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: surajjavarat17@gmail.com

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 dladlzn@gmail.com

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...

nfgfgnfng

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...

SUTESH BHAI KI JAI..........

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...
thanks.

Sandeep Yadav said...

How to add text editor in windows form by vb.net
sandeep yadav
sandeepyadav.bca@gmail.com

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...

jhjh
jhjh
kkjk
kkkm

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 vb.net

sandeepyadav.bca@gmail.com

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 ..do 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...

Hi..

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...

Suresh

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

Give your Valuable Comments

Other Related Posts

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