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

I have PrivateMessage-System in my new Community-Page.

I have a Multiline-Textbox for the Text of a private message.
I save this text in a string, this string in a ntext SQL-Coloumn.
I read this text from the ntext SQL-Coloum in a string and show it in a label.

When I have 5 linebreaks with the “Enter”-Key in my Multi-line-textbox, the linebreaks will disappeared in the label.

I don’t know where they gone lost and what I am doing wrong.
any idea?


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

First of all is it actually saving the line breaks to your table? If so, what does it save them as, eg rn 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("rn", "<br />");

Or even better, do the .Replace() before you save it to the database:
someDatabaseField = TextBox1.Text.Replace("rn", "<br />");

Method 2

You can solve this with CSS. Assign this CSS to your label:

white-space: pre-wrap;

Method 3

this also works:

lbl_PostContent.Text = lbl_PostContent.Text.Replace(vbCrLf, "<br />")

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x