How do you preserve line breaks from a textarea control to a asp:literal?

markerasmus used Ask the Experts™
I am saving data with line breaks from a textarea control to a SQL Server 2008 database.  I have queried the DB and the data is being saved with square bracket characters representing line breaks.  When this data is binded back to a textarea control the line breaks are preserved.

However, if I bind the data to a asp:literal control the line breaks are not preserved.  

How do I preserve the line breaks when pulling data from SQL that was saved from a textarea control? I was thinking about do a replace for vbcrlf but the line breaks are being saved as square bracket characters rather than vbcrlf.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Replace them with chr(10) and/or chr(13). See here:




I tried that and it didn't work:

If Not ld.First.Profile Is Nothing Then litProfile.Text = ld.First.Profile.ToString.Replace(Chr(13) + Chr(10), "VbCrLf")

I also replacing Chr(13) and Chr(10) individually.  The square indicating line breaks still persists.

Any other ideas?

As long as your literal uses Mode=PassThrough (default) or Mode=Transform you could replace the linebreaks with "<br>" and it would insert an html linebreak.

Note: Mode="Encode" encodes your literal text to html and will not work for a <br> linebreak
11/26 Forrester Webinar: Savings for Enterprise

How can your organization benefit from savings just by replacing your legacy backup solutions with Acronis' #CyberProtection? Join Forrester's Joe Branca and Ryan Davis from Acronis live as they explain how you can too.


Thanks, but how do I replace the square character with "<br />"?  chr(10) and chr(13) don't do it.
string holder = TextBox1.Text;
                holder = holder.Replace("\r\n", "<br />");
                Literal1.Text = holder;


Thanks nullcory. ...ld.First.Profile.ToString.Replace(Chr(10), "<br />") worked.

You're going to have a lingering Carriage Return ("\r" or Chr(13)) but it should be of no consequence.
But if you want it gone you could do this
ld.First.Profile.ToString.Replace(Chr(13)+Chr(10), "<br />")
ld.First.Profile.ToString.Replace("\r\n","<br />")

\r is the escape sequence for Chr(13) (carriage return)
and \n is the escape sequence for Chr(10) (line feed)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial