Link to home
Start Free TrialLog in
Avatar of Keiko08
Keiko08Flag for United States of America

asked on

Textbox formatting in ASP.Net C# Javascript

Hello EE,
On a website I am working on I built a comment system that works great, except when the user submits their comment it loses all formatting, example, you can press Enter or Return in the textarea and it starts a new line, but when the insert into the database happens there is no new line so the comments are being displayed goofy, where the user presses enter there is no space or anything.

Can I do anything to resolve this without having to monitor every key stroke in the textarea?

Thanks in Advance!
Avatar of Pratima
Pratima
Flag of India image

Replace the new line with <br> as you want ahow the data in html

variable.Replace(System.Environment.NewLine, "<br>")

Or

variable.Replace("\n", "<br>")
Avatar of Keiko08

ASKER

Woops I completely misworded that, I meant a textarea, doesn't seem to be working for the textarea, I am sending the contents of the textarea using a querystring (ajax)
Hello

Try this if i understand ur problem well

textarea.text = Server.HtmlDecode(Request.QueryString("stringname"))

neeraj523


What pratima suggested will work for a textarea as well
use this.

Supposing u have one label where u want to show data named lblText.
tempVar is variable holding database column value.


VB code
lblText.Text = tempVar.Replace(vbCrLf, "<br />")

ASKER CERTIFIED SOLUTION
Avatar of samtran0331
samtran0331
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial