Reputation: 697
On aspx page I have asp:textbox multilined, where I type data. When I assign TextBox1.text to a string i get something like this:
"line1\r\nline2\r\nline3"
But if I try to set it back to literal, I get:
line1 line2 line3
(without the line barkes)
How to solve it? Is the only way to replace the \r\n with <br />
?
A note: If I store the in put in database (sqlserver), and open the table in sql management studio -> edit rows-> I see string line1line2line3 (all together), but if try to copy to clipboard this content (Ctrl+C) only line1 is copied! Why?
Also, If i bind this data to a repeater, and Eval("myfield") to repeater I get the line brake!
Upvotes: 0
Views: 3611
Reputation: 415820
Here's the trick. Your input is like this:
I have asp:textbox multilined
But your output is like this:
I try to set it back to literal
A literal control just renders raw html, and raw html ignores line breaks. The multi-line textbox renders as an html textarea
element, and the value of a textarea respects line breaks.
Upvotes: 0
Reputation: 7937
In C#
string htmlFormattetText = textStringFromDB.Replace("\r\n","<br />")
or in SQL
SELECT REPLACE(TextCol,'\r\n','<br />' FROM MyTable
Upvotes: 1