Render text with line breaks

  • Thread starter Thread starter Lloyd Sheen
  • Start date Start date
L

Lloyd Sheen

I have text which I need to render to a page. The text is stored in SQL
Server and contains CR/LF's. I need to display the text maintaining the
line breaks. What would be the best method to do this. I have tried labels
and replacing the CR/LF with a </br> but the resulting HTML does not contain
the </br> tags.

Lloyd Sheen
 
Changing to <br/> did not help.

Protected WithEvents lblVendorText As System.Web.UI.WebControls.Label

Dim psTmp As String = Replace(poVI.VendorText, vbCrLf, "<br/>")
lblVendorText.Text = poVI.VendorText

During debugging I can see the <br/> tag in the psTmp variable but rendered
page shows no line breaks.

Lloyd Sheen
 
Well, of course it's not working. You are assigning the label's text to
poVI.VendorText, instead of psTemp. So it's just displaying the original.
 
Your second theory is correct - you need to replace all CRLFs with <br>
tags. If it isn't working, you're llooking for the wrong character(s). Try
using Environment.NewLine for the character to replace.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
 
Just because it's fun to give bad advice:
You could always blast the text directly into a <pre> tag, or (better) use a
css style with "whitespace: pre;" on the element you put the text into. This
is probably far dirtier than the <br> replacement, but it can be workable if
you're lazy like me.
 
Back
Top