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. |
|||
|
|||
80 comments :
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
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.
Thank u very much sir ..Ur Great..It helped me a lot..
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
thanks so lot dear. Its really so good and excellent. thanks again.
Raja chaturvedi
Email-krishraja88@gmail.com
please add with me at facebook
krishna chaturvedi gonda up
or
send
invitation at-krishnachaturvedimca@gmail.com
@subhash
check the below post to solve your problem
http://www.aspdotnet-suresh.com/2011/12/potentially-dangerous-requestform-value.html
Hi Suresh,
Thank you very much for this article. It is simply good.
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......
After enter the data that will store it in database.then how to edit the typed content?
in your above exercise can you explain with vb coding instead of C#...
required validations not working either through jquery or through fieldvalidators.
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
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
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
sir,,this code not working....
how to use fck editor in our web site insert data through fck editor or show data into fck editor
can u tel me how to use it in the wpf,c#
What is the coading og Logout in aasp dot net using c#?
How to create a rich tex in asp dot net using c#?
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?
Sorry, problem solved:)
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?
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?
in the case of mvc how is doing
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"...").
how to disalble right click and Copy,paste options in free text box?
gkhghghghg
gjghjhjh
kjbjhbjhjh
jhjhjhjhhjhjh
456789076543245678
Master Of asp.net
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.
How to retrieve freetextbox placed in gridview
ccccccccc
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
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
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
nfgfgnfng
i just want how to insert image from local drive to rich text box.......
i just want how to insert image from local drive to rich text box.......
SUTESH BHAI KI JAI..........
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....
Sir, I want a particular record from the database that we already inserted into database....please help me...
thanks.
How to add text editor in windows form by vb.net
sandeep yadav
sandeepyadav.bca@gmail.com
How Can I Implement With Jquery..
plz suggest me other free Editor bcoz this editor is conflict with my other Ajax control.
jhjh
jhjh
kkjk
kkkm
Nice application .. You are genious.
Good example,
Hi suresh can you provide code for Downloading functionality as you provide in your article just like( Download sample code attached)
Really Good Post. Thanks
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 ....
How to add text editor in windows form by vb.net
sandeepyadav.bca@gmail.com
I have a problem:
error is:
A potentially dangerous Request.Form value was detected from the client (adminmaster_ftxtname="<font color="#000080...").
how do i use that downloaded dll ..do i have to install it or where do i place it
please help
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
MVC 3.0 the FreeTextBoxControls showing disabled
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.
Hi Suresh, may i know why we are using the free rich text control when we have it is asp. ajaxcontroltoolkit
Hi suresh, this control is not working in ie 10 browser with document mode as standard.
plz reply
Hi suresh really nice work..
is there any validation for maxlenght?
please suggest me something
can any one suggest me how set max length of rich textbox?
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
hello there, thanks for TB, how can I add more fonts, colors and other styles in it.
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.
i got the error Microsoft JScript runtime error: Permission denied how can i solve it
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
Suresh
in ie 11 it is not working........
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
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?
Problem with license :(
Problem with license :(
How to search in Databse from richtextdata pls help
On Hyper Link I want session
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,
Amit
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
Can we read the content with images in the word document and display in richtextbox in runtime?
HI,
I have to create html thru Rich text box and save to database and how to save image from rich text box in database
HI
any one can help me to add dll file to in my project..
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. "
How to find the maxlength for this richtextbox ? Any built in method or writing a code is the only option ?
Thank you sir this code is working fine.
Suresh bhai, is the "FreeTextbox.dll" can be used inside windows hosting providers. This will support or not
Note: Only a member of this blog may post a comment.