Render text with line breaks

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
 
L

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
 
M

Marina

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.
 
K

Kevin Spencer

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
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top