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

1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.