Line breaks in Textbox go missing when transfered to label

Posted on 2006-05-18
Medium Priority
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

mrichmon earned 2000 total points
ID: 16713783
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

ID: 16713785
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Integration Management Part 2
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month16 days, 11 hours left to enroll

862 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