ASP.Net Text with LineBreak from Multi-Line-TextBox to save in a database

First of all is it actually saving the line breaks to your table? If so, what does it save them as, eg \r\n or CRLF or what?

Your label outputs html, so the only thing that will create a break is a <br /> tag. So you need to find and replace whatever is saved in the database:

Label1.Text = someDatabaseText.Replace("\r\n", "<br />");

Or even better, do the .Replace() before you save it to the database:

someDatabaseField = TextBox1.Text.Replace("\r\n", "<br />");

Leave a Comment