views:

105

answers:

3

I am using ASP.NET 2.0 with SQL Server 2005.

My page have a text box where TextMode="MultiLine"......see below

alt text

Now when I save this text in my database of course it does not save it with any HTML tags, and thus when i read that value from the database it comes back as 1 line such as....

Hello word, It needs to look like this. Thanks!

But I want it to be dispayed just like the user typed it. Is there no out of box control that will do this for me rather than me using Ajax or jQuery?

Thanks in advanced!

+3  A: 

Like that?

 myString.Replace("\n", "<br />");
Ahmet Kakıcı
The problem comes in in showing the data in a label instead of a textbox. Textboxes display text in "plain text", labels (which render as spans) display it in HTML. Plain Text uses Char(13) for carriage return, where as HTML uses the character sequence "<br/>". They aren't talking the same "language". Ahmet's solution is a way of translating between them.
eidylon
+1  A: 

From your comment to my question, the problem doesn't lie with the DB not storing your data properly. But rather you displayed it in a manner which doesn't reflect the true representation of the data.

As I've commented in your post, "If you output it as HTML, the line break is not going to be rendered, it's just a whitespace."

What Ahmet has answered will one of the methods to have your linebreaks rendered in HTML.

If you assign the retrieve value into a textarea or multiline textbox, you will have the linebreaks displayed without manipulating the string.

o.k.w
How or where do you assign the retrieve value for a ASP.NET text box?
Etienne
`textboxMultiline.Text = ValueFromDatabase`
o.k.w
MMMM, and I cant write this to a label?? Because I dont want to display it inside a text box.
Etienne
To write to a label, you have to replace linebreaks with `<br />`s.
o.k.w
But when i save the value of the text box into the database there is no line break tags. I save it like so.....ValuetoDatabase = txtName.text
Etienne
+1  A: 

You should store CRLF characters in the database because these are part of your data, and replace them with BR tags on display because it's a HTML/presentation issue.

The same applies for multiple spaces and other data. Do you have expect brackets in your text box, for example?

gbn