Using html tags pulled from an Access database in ASP page

B

BCS

I have a web site in which the site administrator can input
information to a database through a web form. The information then
gets displayed on ASP pages. One field is a large text field. Of
course, without html tags, the text gets displayed on the web page as
one long paragraph since the database doesn't store any line breaks or
paragraph breaks. The obvious solution (to me) is to use html tags
like <br> in the input. However, while this information gets stored
in the Access database correctly, when it gets pulled out the page
displays the actual tag on the page. In other words, it actually
converts the "<" to "&lt;" in the html so that it displays as "<" on
the web page.

I'm more used to working with PHP where I didn't have this problem,
and I'm sure there is a simple solution, but I've scoured the web and
my ASP books and can't seem to find the answer.
 
A

Aaron [SQL Server MVP]

like said:
in the Access database correctly, when it gets pulled out the page
displays the actual tag on the page. In other words, it actually
converts the "<" to "&lt;" in the html so that it displays as "<" on
the web page.

What is "it"? Can you show the code that causes this bizarre symptom?

Anyway, if you store plain text carriage returns in the database, you don't
need to teach all of your users HTML. Just replace them with HTML carriage
returns when you DISPLAY the data. http://www.aspfaq.com/2188
 
B

BCS

Aaron said:
What is "it"? Can you show the code that causes this bizarre symptom?

Anyway, if you store plain text carriage returns in the database, you don't
need to teach all of your users HTML. Just replace them with HTML carriage
returns when you DISPLAY the data. http://www.aspfaq.com/2188

"it" is simply the text from the access database. All I am doing is
trying to display a text field from the Access database onto a web
page. So maybe it's an Access question. How do you get the Access
database to store the carriage returns from the web form input page?
 
J

Jeff Cochran

"it" is simply the text from the access database. All I am doing is
trying to display a text field from the Access database onto a web
page. So maybe it's an Access question. How do you get the Access
database to store the carriage returns from the web form input page?

It already does. Except that for display you need HTML carriage
returns, either <P> or <BR> tags. Read the link Aaron posted and do
it.

Jeff
 
A

Alan Howard

If a user enters a carriage return in a textarea it will be stored - no need
to worry about the how. Keep in mind that you want to separate the content
(what they type in) from the presentation (how or where it gets displayed).
Take whatever they type into the textarea and shove it into the database.
Transform it appropriately depending on what it's used for *after*
retrieving it. If you're displaying it on a web page then you can replace
vbCrLf pairs with <br> tags and Server.HTMLEncode the rest.

Alan

BCS said:
What is "it"? Can you show the code that causes this bizarre symptom?

Anyway, if you store plain text carriage returns in the database, you don't
need to teach all of your users HTML. Just replace them with HTML carriage
returns when you DISPLAY the data. http://www.aspfaq.com/2188

"it" is simply the text from the access database. All I am doing is
trying to display a text field from the Access database onto a web
page. So maybe it's an Access question. How do you get the Access
database to store the carriage returns from the web form input page?[/QUOTE]
 
A

Aaron [SQL Server MVP]

What is "it"? Can you show the code that causes this bizarre symptom?
"it" is simply the text from the access database. All I am doing is
trying to display a text field from the Access database onto a web
page. So maybe it's an Access question. How do you get the Access
database to store the carriage returns from the web form input page?

I will repeat what I said before. You don't do anything to store the
carriage returns any differently. You simply replace them with HTML
carriage returns (<br>) when you DISPLAY the text. If you read the link I
posted, you will understand, perhaps, what I mean.

If not, I will ask once more, with a little emphasis on the part of this
equation we need in order to help you.

Can you *****///SHOW THE CODE///***** that causes this bizarre symptom,
instead of describing it with narrative? Do you know how many different
ways one could interpret, "All I am doing is ... "?
 
B

BCS

Aaron said:
I will repeat what I said before. You don't do anything to store the
carriage returns any differently. You simply replace them with HTML
carriage returns (<br>) when you DISPLAY the text. If you read the link I
posted, you will understand, perhaps, what I mean.

If not, I will ask once more, with a little emphasis on the part of this
equation we need in order to help you.

Can you *****///SHOW THE CODE///***** that causes this bizarre symptom,
instead of describing it with narrative? Do you know how many different
ways one could interpret, "All I am doing is ... "?

Actually, the that was supplied did explain what to do very well and
it did work. I put up the last post just to clarify my original post
since there seemed to be a little confusion about what I was asking.
I probably should have waited until I had a chance to go through the
suggested article (and, yes, I should have provided the code as
requested. I've provdided both the before and after code below so
people with the same problem can quickly see the correction.


ORIGINAL CODE
<%
Dim Conn, cStr, sql, number
number = [response.write request("number")]
set conn = Server.CreateObject("ADODB.Connection")
cStr = "DRIVER={Microsoft Access Driver (*.mdb)};"
cStr = cStr & "DBQ=" & Server.MapPath("../../db/database1.mdb") & ";"
Conn.Open(cStr)
sql = "SELECT * FROM jobs WHERE ""job number"" = '" &
request("number") & "'"
set rs = conn.execute(sql)
do while not rs.eof


description = rs("description")
response.write(description)
rs.movenext
loop
%>

NEW CODE

<%
Dim Conn, cStr, sql, number
number = [response.write request("number")]
set conn = Server.CreateObject("ADODB.Connection")
cStr = "DRIVER={Microsoft Access Driver (*.mdb)};"
cStr = cStr & "DBQ=" & Server.MapPath("../../db/database1.mdb") & ";"
Conn.Open(cStr)
sql = "SELECT * FROM jobs WHERE ""job number"" = '" &
request("number") & "'"
set rs = conn.execute(sql)
do while not rs.eof
description = rs("description")
response.write(replace(description, CHR(10), CHR(10) &
"&nbsp;<br>"))

rs.movenext
loop
%>
 
R

Roland Hall

: Anyway, if you store plain text carriage returns in the database, you
don't
: need to teach all of your users HTML. Just replace them with HTML
carriage
: returns when you DISPLAY the data. http://www.aspfaq.com/2188

chr(10) is a line feed, not a carriage return (chr(13)), so shouldn't you be
using vbCrLf?
response.write(replace(memocolumn, vbCrLf, vbCrLf & "<br />"))

and why is the non-blanking space included?

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
A

Aaron [SQL Server MVP]

chr(10) is a line feed, not a carriage return (chr(13)), so shouldn't you
be
using vbCrLf?

Depending on the source, it's not always a full vbCrLf, and it's not always
paired in the right order. So I picked one of the two.
and why is the non-blanking space included?

It's a non-breaking space, and it is used because if multiple line breaks
were intended, IE et. al. would ignore successive <br>'s, but they won't
ignore successive <br>'s separated by &nbsp;.
 
S

Stuart Grant

What you need to do is to is when you write the 'HTML'
code you want to the page

strText = Rs("memofield")
strText = Replace(strTExt,vbCrLF,"<br>")

This way when the administrator edits the code he/she will
still be able to view the line break in the text area box

HTH
 

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

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top