Line breaks in Textbox go missing when transfered to label

Posted on 2006-05-18
Last Modified: 2012-05-05
I have a text box where people post stuff and they write lines and press the ENTER button for ne wlines and write more lines etc .
I then save the text in the database when they press the update button.
the problem is when i go to read from the database and display the text in a label the lable shows it as one big text block with out the new lines?  How do i save it to database pproperly or get the line breaks to show up int he label or something?
Question by:joshuadavidlee
    LVL 35

    Accepted Solution

    It is most likely saving to the database properly - with newlines.

    However, when you display on a web page then new lines are whitespace, which is ignored.

    So you simply need to do something like this:

    LabelName.Text = datasbaseText.Replace(Environment.NewLine, "<br>");
    LVL 10

    Expert Comment

    the text in a label needs to use the html tags <BR> to show a line break.

    You'll need to parse it.

    One way is if you return data from a database try

       replace(MyColumn, char(13), '<BR>')

    from MyTable

    where ...

    Alternatively you can parse it yourself:



    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now