markerasmus
asked on
How do you preserve line breaks from a textarea control to a asp:literal?
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.
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.
ASKER
I tried that and it didn't work:
If Not ld.First.Profile Is Nothing Then litProfile.Text = ld.First.Profile.ToString. Replace(Ch r(13) + Chr(10), "VbCrLf")
I also replacing Chr(13) and Chr(10) individually. The square indicating line breaks still persists.
Any other ideas?
If Not ld.First.Profile Is Nothing Then litProfile.Text = ld.First.Profile.ToString.
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
Note: Mode="Encode" encodes your literal text to html and will not work for a <br> linebreak
ASKER
Thanks, but how do I replace the square character with "<br />"? chr(10) and chr(13) don't do it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks nullcory. ...ld.First.Profile.ToStri ng.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(Ch r(13)+Chr( 10), "<br />")
or
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)
But if you want it gone you could do this
ld.First.Profile.ToString.
or
ld.First.Profile.ToString.
\r is the escape sequence for Chr(13) (carriage return)
and \n is the escape sequence for Chr(10) (line feed)
Cheers,
Lee