Displaying carriage returns in a memo field

L

Les Juby

Can someone please help with a suggestion as to how I can keep the
formatting (carriage returns) that the user enters into a memo field
and then display that later.

I figured I might be able to use:
'replace carriage returns with BRs
comment=Replace(comment, chr(13), "<br>")
but obviously net.!

The <pre> tag doesn't sem to help either as the embedded return is
lost by the time you get past Request.Form......

thanks

.les.
 
A

Aaron Bertrand [SQL Server MVP]

I've never had a problem using Replace(), but I use chr(10) or vbCrLf, not
chr(13). I also only doing this when *displaying* the data, not when
storing it. I'm not sure why you think "the embedded return is lost"
because it is not. Could you show some sample code that reproduces this
problem?

http://www.aspfaq.com/2188

A
 
L

Les Juby

Uuuuuuhh..... it was the chr(13) instead of chr(10)

A throwback to dBase and the old DOS days.

Works great, thanks for the help !

.les.
 
D

Dave Anderson

Aaron said:
I've never had a problem using Replace(), but I use chr(10)
or vbCrLf, not chr(13). I also only doing this when
*displaying* the data, not when storing it. I'm not sure why
you think "the embedded return is lost" because it is not.
Could you show some sample code that reproduces this problem?

Since the OP did not elaborate, I would like to offer this observation:
*Leading* carriage returns are not rendered by some browsers[1], meaning
they must be accounted for in post-back situations.

In other words, if you have something like this...

<textarea name="txt"><%=Request.Form("txt").Item%></textarea>

....and type the equivalent of "\r\nTest\r\n" (or: vbCrLf & "Test" & vbCrLf),
then the resulting HTML source is...

<textarea name="txt">
Test
</textarea>

....which is rendered in the browser identically to this:

<textarea name="txt">Test
</textarea>



Note that the carriage return was not lost in the form submission, as the
resultant HTML source properly contains it. Furthermore, the *trailing*
carriage returns are retained. It is an oddity, but not the only one.
Displaying the text outside the form control is a whole other animal.

Consider what happens when the following are added to my example:

<style type="text/css">
div { border:solid 1px #ccc; white-space:pre; }
pre { border:solid 1px #ccc; }
</style>
<div><%=Server.HTMLEncode(Request.Form("txt").Item)%></div>
<pre><%=Server.HTMLEncode(Request.Form("txt").Item)%></pre>
<div><%=Request.Form("txt").Item%></div>
<pre><%=Request.Form("txt").Item%></pre>

In all tested browsers, neither leading nor trailing carriage returns are
rendered <pre> in here </pre>. IE treats <div style="white-space:pre;">
identically. Opera and Firefox retain the leading carriage returns, but lost
the trailing ones. In all three browsers, the "white-space:pre" rendering
conflicts with that of <textarea>. It's no wonder the OP might think his
carriage returns are being lost.



[1] IE and Firefox, at a minimum. Opera does not lose them. UAs tested:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; en) Opera 8.01
Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.10) Gecko/20050716
Firefox/1.0.6
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322;
..NET CLR 1.0.3705; .NET CLR 2.0.40607)

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
B

Bullschmidt

Here's what has worked for me although I usually put it into a function:

' Convert all vbCrLf to <br>.
' (This is the same as converting Chr(13) & Chr(10) to <br>.)
varFld = Replace(varFld, vbCrLf, "<br>")

Best regards,
J. Paul Schmidt, Freelance ASP Web Developer
http://www.Bullschmidt.com
ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...

<<
Can someone please help with a suggestion as to how I can keep the
formatting (carriage returns) that the user enters into a memo field
and then display that later.

I figured I might be able to use:
'replace carriage returns with BRs
comment=Replace(comment, chr(13), "<br>")
but obviously net.!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top