Ryan
Ryan

Reputation: 18109

Newline in textarea in DetailsView (asp.net)

I just updated a page to use a DetailsView in asp.net. It included a MultiLine textbox, which is now in the EditItemTemplate of the details view. The problem is that when outputting this data (which is stored in the database), I was replacing vbCrLf (a new line contant --> VB, Carriage Return, Line Feed) with <br/>, which worked fine before, but now that it is in the details view its like the vbCrLf doesn't exist and after the replace(str, vbCrLf, "<br/>"), instead of there being a HTML break (<br/>) where the textbox had linebreaks, it all just displays in one line. How can I fix this? Thanks.

Upvotes: 0

Views: 2976

Answers (5)

drs9222
drs9222

Reputation: 4508

Try Environment.NewLine instead

Upvotes: 1

zakster82
zakster82

Reputation: 244

I've always replaced the character code--chr(10) in VB.NET--with a <br /> to show my line breaks. Give that a try?

Upvotes: 0

Canavar
Canavar

Reputation: 48088

With a textarea control, the long texts seems like they have line breaks, but sometimes they don't have line breaks. If the text reaches the length of the text area, it continues at the second line, but it's not contain a line break. If user presses enter, then a new line break will be added to your content.

I think you're missing that point.

Hope it helps.

Upvotes: 0

Nicholas Franceschina
Nicholas Franceschina

Reputation: 6147

if you're taking data out of the database, that contains newlines, then just leave those there and the textArea should work just fine... you don't need to do a replace with "<BR/>"... you only need to do that if you're putting the text into the page as HTML... but you're trying to fill an input control, so unless you're doing something else that isn't clear, you don't need to do the replace

Upvotes: 0

David
David

Reputation: 73564

Set the htmlEncode to false

Upvotes: 0

Related Questions