开发者

Value from text box not saved properly in database

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

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

alt text http://www.erateusa.com/Textbox.bmp

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 ra开发者_开发问答ther than me using Ajax or jQuery?

Thanks in advance!


Like that?

 myString.Replace("\n", "<br />");


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.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜