1

I have an ASP.net 4.5 text box with 5 rows. When I save the below data to my table it does not take in consideration that there are line breaks.

Example:

Hello my name is Mike! How are you?

Please can you help?

When saving this data to my table it of course save it like this below and it will be displayed like this again if I populate my website with this value.

Hello my name is Mike!How are you?Please can you help?

But I want it to be displayed with the line breaks as the way it was written in the first place.

The thing is, I do not want to make use of a custom form item because then the user will be able to copy and paste all html from another website in and I do not want that.

Any idea how this can be done without using a plugin such as below where the user will be able to copy and paste data into?

enter image description here

Etienne
  • 7,141
  • 42
  • 108
  • 160
  • 2
    http://stackoverflow.com/questions/296849/line-break-in-textbox-or-html-area http://stackoverflow.com/questions/4883613/asp-net-text-with-linebreak-from-multi-line-textbox-to-save-in-a-database http://stackoverflow.com/questions/20536431/save-the-value-from-multiline-textbox-into-sql-server-with-line-brea – clweeks Apr 29 '15 at 14:06

1 Answers1

2

To populate your text box from the database try;

TextBox1.Text = someText.Replace("\r\n", Environment.NewLine)

For Label

Label1.Text = someText.Replace("\r\n", <br />)

Alternatively you could save the data to your database with the

someText = TextBox1.Text.Replace("\r\n", "<br />")

Although this approach may not be appropriate if the database is also used elsewhere.

DG123
  • 76
  • 6