Render text with line breaks

Discussion in 'ASP .Net' started by Lloyd Sheen, Sep 22, 2004.

  1. Lloyd Sheen

    Lloyd Sheen Guest

    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
     
    Lloyd Sheen, Sep 22, 2004
    #1
    1. Advertising

  2. First off, it's <br /> . Second off, you'll need to post some code.
     
    =?Utf-8?B?U2NvdHQgU2ltb25z?=, Sep 22, 2004
    #2
    1. Advertising

  3. Lloyd Sheen

    Lloyd Sheen Guest

    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
    "Scott Simons" <Scott.Simons.At.MealMagic.Com.Remove.This> wrote in message
    news:...
    > First off, it's <br /> . Second off, you'll need to post some code.
     
    Lloyd Sheen, Sep 22, 2004
    #3
  4. Lloyd Sheen

    Marina Guest

    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.

    "Lloyd Sheen" <> wrote in message
    news:Nii4d.3584$...
    > 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
    > "Scott Simons" <Scott.Simons.At.MealMagic.Com.Remove.This> wrote in

    message
    > news:...
    > > First off, it's <br /> . Second off, you'll need to post some code.

    >
    >
     
    Marina, Sep 22, 2004
    #4
  5. 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

    "Lloyd Sheen" <> wrote in message
    news:bPh4d.41502$...
    > 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
    >
    >
     
    Kevin Spencer, Sep 22, 2004
    #5
  6. Lloyd Sheen

    Lloyd Sheen Guest

    Thanks, takes someone else to see the simple things.

    Lloyd Sheen

    "Marina" <> wrote in message
    news:%...
    > 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.
    >
    > "Lloyd Sheen" <> wrote in
    > message
    > news:Nii4d.3584$...
    >> 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
    >> "Scott Simons" <Scott.Simons.At.MealMagic.Com.Remove.This> wrote in

    > message
    >> news:...
    >> > First off, it's <br /> . Second off, you'll need to post some code.

    >>
    >>

    >
    >
     
    Lloyd Sheen, Sep 22, 2004
    #6
  7. 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.

    "Lloyd Sheen" wrote:

    > 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
    >
    >
    >
     
    =?Utf-8?B?SmVyZW15IERhdmlz?=, Sep 22, 2004
    #7
  8. Correction: the css style rule is "white-space:pre;" with the hyphen.

    "Jeremy Davis" wrote:

    > 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.
    >
    > "Lloyd Sheen" wrote:
    >
    > > 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
    > >
    > >
    > >
     
    =?Utf-8?B?SmVyZW15IERhdmlz?=, Sep 22, 2004
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Herbert Gerstinger

    Text with automated line-breaks for a picture

    Herbert Gerstinger, Aug 7, 2005, in forum: HTML
    Replies:
    26
    Views:
    800
    Toby Inkster
    Aug 9, 2005
  2. David Blickstein

    Line breaks in text mode for XSLT

    David Blickstein, Jun 28, 2005, in forum: XML
    Replies:
    5
    Views:
    2,207
    Peter Flynn
    Jul 3, 2005
  3. David

    Using line breaks in text

    David, Oct 18, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    417
    Russell
    Oct 19, 2006
  4. bernadou

    Force multi line field value to output with line breaks?

    bernadou, Jan 22, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    391
    bernadou
    Jan 23, 2006
  5. Marek Stepanek
    Replies:
    12
    Views:
    437
    Peter J. Holzer
    Sep 2, 2006
Loading...

Share This Page