Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi .
i want to save formatted text in database using c# in asp.net .
below code save text in data row :
C#
dr.fContent=txtContent.Text;

and now i want to fetch my content from table and represent in Lable Control by Data binding :
ASP.NET
<asp:Label ID="lblContent" runat="server" Text='<%# Eval("fContent")%>'></asp:Lable>


but if i enter formatted text doesn't work correctly
for example if i enter :
1
2
3
then show 123 !
Posted
Updated 7-Mar-12 21:09pm
v2
Comments
Herman<T>.Instance 8-Mar-12 3:12am    
for html there is a big difference between /r/n and <br />

That is because '\n' means nothing to the browser - it is just whitespace which can be removed. Consider using string.Replace to change it to an HTML newline:
C#
dr.fContent = txtContent.Text.Replace("\n", "<br />");
 
Share this answer
 
Comments
Saeid.Babaei86 8-Mar-12 3:17am    
thanks .this is correct .

but i have another problem . now if i want to save html tags icluded text such as <html> i get below problem :

" A potentially dangerous Request.Form value was detected from the client... "
i dont want to disable page ValidationRequest . what i do ?
bala.vanchi 9-Mar-12 1:37am    
I hope below link will be useful to resolve this
http://www.codeproject.com/Tips/297679/A-potentially-dangerous-Request-Form-value-was-det
Hellow, Generally, textbox won't allow to save formatted text. rather use richtext box control which will allow you to enter the formatted text the retrieve it back. but still you want to do it in a formatted way.. you have enter it as html tags like Text
and so on..
 
Share this answer
 
Instead of TextBox, you can use RichTextBox. Refer CodeProject article at: C# - Formatting Text in a RichTextBox by Parsing the Rich Text Format (RTF)[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900