Character Returns not loading on form

  • Thread starter Thread starter Susan Geller
  • Start date Start date
S

Susan Geller

Character returns stored in a table do not display in a textbox or on a
datagrid on my .net form. The text displays without the returns making the
text difficult to read. When I "view source" on the page, I see the returns
and when I view the data in Enterprise Manager I can also see the returns.
I have the same problem when I am looking at the text in a datagrid and when
I am looking at it in a textbox.

Example:
Text in database:
"some text

and then some more text after a two character returns"

displays like this:
"some text and then some more text after a two character returns"

--Susan
 
This is because carriage returns in a database are not the same as carriage
returns in HTML. You would have to scrub the string and replace carrige
returns with <BR> for it to render properly in html:

dbString.Replace(Environment.NewLine, "<br>")
 
An HTML document is text underneath it all, but in the browser, it is an
HTML document. Therefore, the text that forms the document falls under the
rules for HTML, one of which is that "white space" characters (any
characters which do not render, such as space, tab, line feed, etc) are
treated as single spaces, regardless of the number of them consecutively) in
the browser. You need to replace CrLfs with HTML-encoding for a line break
("<br>").

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Is this an inpu type="text" or a textarea? Same question, different way: is
thie textmode of your textbox MultiLine?

Karl
 
FYI -- Bryant's line of code worked just fine. Rendered correctly. Thanks,
all.

dbString.Replace(Environment.NewLine, "<br>")

--Susan
 
Back
Top