Display text with line breaks that is typed in Multiline Asp.Net TextBox in HTML
When we capture the user's comments through multiline textbox, the comments will not display the line breaks correctly when it is displayed on the page. Whenever the users hits the enter button there is line break(\n) added. These line breaks will get saved as "\r\n" in the database field. Alos, this line break character when displayed back will not break the line since browser will not understand it. Browser only understand HTML tag which <BR> in this case.
To display the line breaks in HTML we need to replace "\r\n" to <br> tag.
The below code will help us to do that.
string str =txtComment.Text.Replace("\r\n","<br>");
Read my previous article on how to allow users to type HTML inputs in textbox in ASP.Net.
|