views:

806

answers:

5

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.

A: 

Set the htmlEncode to false

David Stratton
on what control?
Ryan
I tried looking at all the involved controls and I don't see an htmlEncode property anywhere
Ryan
A: 

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

Nick Franceschina
Hey, sorry if I wasn't clear... I am outputting this data elsewhere. It works fine when I put it back in the textarea. In there, it has line breaks. When I output to HTML elsewhere (not in textarea), that's when I'm doing the replace with <br/> but its not finding the vbCrLf
Ryan
A: 

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.

Canavar
No I completely understand that point... thats the opposite of my question. I want to get the line breaks that the user does enter. For example, when user types line 1(hits return)line 2... I want to replace those line breaks with HTML line breaks (<br/>) when I am outputting it to a page. I know text will word-wrap, that's not an issue.
Ryan
Like I said, it had it working fine before it was in a DetailsView, but for some reason the details view seems to be changing the vbCrLf character (which I was replacing with <br/> and that is exactly what I wanted) with some other line break character, which is not vbCrLf and therefor is not getting replaced with <br/> when outputting to a page.
Ryan
A: 

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

zakster82
Hi, how do you replace the character code? I tried Replace(stringField, char(10), "<br/>") but it says char is a type and cannot be use as an expression.
Ryan
zakster82 said chr(10) not char(10). I personally use C# so I'm not sure about this but I believe that chr is an old vb function for converting an integer to an ascii character. I'm not sure if it exists in VB.NET.Since I am also not sure if you are using VB.NET or C# I would suggest something like System.Convert.ToChar(10) which I think will work in either.
drs9222
A: 

Try Environment.NewLine instead

drs9222
thanks for the suggestion but this doesn't seem to work either. Does linq replace it with something else? Because the textarea still seems to know the line break is there but replacing vbCrLf, Environment.NewLine, etc etc doesn't seem to know its there.
Ryan
I don't know if linq would do anything like that. I just made a quick test where I read the value, did the substitution and output the new value and that worked just fine. Maybe you should try debugging on both ends to see what the actual value of the string is.
drs9222