CODEDIGEST
Home » CodeDigest
Search
 

Technologies
 

Display text with line breaks that is typed in Multiline Asp.Net TextBox in HTML
Submitted By Satheesh Babu B
On 11/28/2008 5:12:04 AM
Tags: ASP.Net,CodeDigest,HTML  

 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.

Do you have a working code that can be used by anyone? Submit it here. It may help someone in the community!!

Recent Codes
  • View All Codes..