ASP rendering wierdness

T

Tek Boy

I've been experiencing some (reproducable) wierdness when I try to generate
some very basic HTML using ASP. Check out the following (basic) ASP code:

===========================================
<% Option Explicit

Const STRING_1 = "/admin/UploadProgress2.asp"
Const STRING_A = "AXFFile" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<%=STRING_A%>.Server = "<%=Request.ServerVariables("SERVER_NAME")%>"
<%=STRING_A%>.Port = <%=Request.ServerVariables("SERVER_PORT")%>
<%=STRING_A%>.ObjectName = "<%=STRING_1%>"
</body>
</html>
===========================================



The problem is that, when I "run" the ASP page and view the HTML source code
that is generated, I get the following:

===========================================

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
AXFFile.Server = "www.nbsc.com"
AXFFile.Port = 80AXFFile.ObjectName = "/admin/UploadProgress2.asp"
</body>
</html>
===========================================



Why do lines 12 (<%=STRING_A%>.Port =
<%=Request.ServerVariables("SERVER_PORT")%>) and 13
(<%=STRING_A%>.ObjectName = "<%=STRING_1%>") appear as a single line in
HTML? Can anybody else reproduce this problem, and if so, do you have any
idea why this is happening? I can always work around it by adding "vbcrlf"
to the end of each line, but I'd rather not work around it...........

Any help would be greatly appreciated..... thanks in advance!


-= Tek Boy =-
 
A

Aaron [SQL Server MVP]

If you want a carriage return, use <BR>.

I couldn't reproduce your issue (it all appears on one line), but please
don't confuse plain text characters with HTML characters...
 
R

Ray Costanzo [MVP]

Reproduced! W2K SP3 server. Same behavior on a WS2003.

I can't explain it. That is a bit bizarre! If I throw in some other
characters at the end of the line, all the line breaks appear in the HTML.

<% Option Explicit %>
<%
Const STRING_1 = "/admin/UploadProgress2.asp"
Const STRING_A = "AXFFile"
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<%=STRING_A%>.Server = "<%=Request.ServerVariables("SERVER_NAME")%>"
<%=STRING_A%>.Port = <%=Request.ServerVariables("SERVER_PORT")%>
<!-- -->







<%=STRING_A%>.ObjectName = "<%=STRING_1%>"
</body>
</html>


The line breaks show up with that. But if I remove the <!-- -->, they do
not.

Ray at work
 
R

Ray Costanzo [MVP]

What he was talking about is how the actual HTML source appears. The HTML
file has:
<%=STRING_A%>.Server = "<%=Request.ServerVariables("SERVER_NAME")%>"
<%=STRING_A%>.Port = <%=Request.ServerVariables("SERVER_PORT")%>
<%=STRING_A%>.ObjectName = "<%=STRING_1%>"

which should appear as

AXFFile.Server = "oldharleyweb"
AXFFile.Port = 80
AXFFile.ObjectName = "/admin/UploadProgress2.asp"

when doing a view source. But instead, it appears as:

AXFFile.Server = "oldharleyweb"
AXFFile.Port = 80AXFFile.ObjectName = "/admin/UploadProgress2.asp"

Ray at work
 
D

Dave Anderson

Tek said:
<%=STRING_A%>.Server = "<%=Request.ServerVariables("SERVER_NAME")%>"
<%=STRING_A%>.Port = <%=Request.ServerVariables("SERVER_PORT")%>
<%=STRING_A%>.ObjectName = "<%=STRING_1%>"

I have seen similar behavior, wherein the space below is "dropped" from the
output:
<%=var1%> <%=var2%>

I get around it with non-breaking spaces...
<%=var1%>&nbsp;<%=var2%>

....or concatenation...
<%=var1 & " " &var2%>

....and assume the reason has to do with optimization by the parser. Note
that in your example, there is a necessary (because of the quote) context
switch between lines 1&2, but the server-side blocks at the end of 2 and the
beginning of 3 could be considered a single block, which appears to be the
way it is processed.


--
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.
 
L

Larry Bud

The problem is that, when I "run" the ASP page and view the HTML source code
that is generated, I get the following:

doesn't do that for me. It appears as it should. Maybe in your copy
there's really not a CRLF in there. Just delete the LF between the
2nd and 3rd statement, and hit enter to put it back.

What does it matter what the HTML looks like?
 
P

Phillip Windell

You need to ad a vbCRLF to the end of the line to force a CRLF at the end of
the line in the raw HTML.
Like this:

<%=STRING_A%>.Server = <%=Request.ServerVariables("SERVER_NAME") & vbCRLF %>
<%=STRING_A%>.Port = <%=Request.ServerVariables("SERVER_PORT") & vbCRLF %>
<%=STRING_A%>.ObjectName = <%=STRING_1 & vbCRLF%>

Without the shortcut form of "response.write" it would look like this:

<%
Response.write STRING_A & ".Server = " &
Request.ServerVariables("SERVER_NAME") & vbCRLF
Response.write STRING_A & ".Port = " &
Request.ServerVariables("SERVER_PORT") & vbCRLF
Response.write STRING_A & ".ObjectName = " & STRING_1 & vbCRLF
%>

If you want the redered HTML to break the same way then add the right "<br>"
at the end.

<%=STRING_A%>.Server = <%=Request.ServerVariables("SERVER_NAME") & "<br>" &
vbCRLF %>
<%=STRING_A%>.Port = <%=Request.ServerVariables("SERVER_PORT") & "<br>" &
vbCRLF %>
<%=STRING_A%>.ObjectName = <%=STRING_1 & vbCRLF%> <br>

Without the shortcut form of "response.write" it would look like this:

<%
Response.write STRING_A & ".Server = " &
Request.ServerVariables("SERVER_NAME") & "<br>" & vbCRLF
Response.write STRING_A & ".Port = " &
Request.ServerVariables("SERVER_PORT") & "<br>" & vbCRLF
Response.write STRING_A & ".ObjectName = " & STRING_1 & "<br>" & vbCRLF
%>
 
S

Saiyan Vejita

doesn't do that for me. It appears as it should. Maybe in your copy
there's really not a CRLF in there. Just delete the LF between the
2nd and 3rd statement, and hit enter to put it back.

What does it matter what the HTML looks like?

It matters because it's trying to assign property values to a
client-side ActiveX component (Software Artisans' XFile). If the two
lines are not rendered as separate lines of code, the ActiveX
component sees it as an invalid assignment statement, and causes the
entire page to fail (where my needs are concerned). Part of the
reason I abhor client-side validation and error-trapping.........
 
S

Saiyan Vejita

Thank you _SO_ much for testing it out, Ray. I can't tell you how
frustrated I when I found out what was happening, even though my
code's syntax was correct. I'm on hold with Microsoft right now, so
we'll see what they have to say about all this, and if there's any
hope for fixing it.


-= Tek Boy=-
 
S

Saiyan Vejita

I know about the spacing behavior you described, and I always
explicitly declare a space (using &nbsp;, or Response.Write) when
trying to separate two server-generated blocks of text. That
"problem" seems to be consistent, though, and is probably by design.

It's not as easy to work around the problem when dealing with
vBcRlf's, though. Sometimes the line-break is rendered, sometimes it
isn't; and according to people in this thread, it occurs on some boxes
and not others. Besides, I really don't want to have to attach
"vBcRlf" to the end of every line of code, just to make sure it's
rendered properly.....


-= Tek Boy =-
 
R

Ray Costanzo [MVP]

Saiyan Vejita said:
I'm on hold with Microsoft right now, so
we'll see what they have to say about all this, and if there's any
hope for fixing it.

Nice! Please post back if they say anything interesting.

Thanks,

Ray at work
 
B

Ben Strackany

Try re-adding the CRLF, and type in some spaces after
<%=Request.ServerVariables("SERVER_PORT")%>.

Or force the CRLFs yourself with

<%
Response.Write STRING_A & ".Server = """ &
Request.ServerVariables("SERVER_NAME") & """" & char(13) & chr(10)
Response.Write STRING_A & ".Port= " & Request.ServerVariables("SERVER_PORT")
& char(13) & chr(10)
Response.Write STRING_A & ".ObjectName = " &
Request.ServerVariables("STRING_1") & char(13) & chr(10)
%>

& avoid the situation entirely.
 
S

Saiyan Vejita

Ray Costanzo said:
Nice! Please post back if they say anything interesting.

Thanks,

Ray at work


So, after a few days of the Microsoft customer service rep looking
into the problem, I'm told what I already know: that, if there's no
visible character appearing on the same line after the closing ASP tag
("%>"), all subsequent whitespace between the "%>" and the next
visible character will be disregarded. The only two solutions are: 1)
to make sure a visible character appears after the "%>" closing tag on
a given line (in my case, a hard-coded <%=vbcrlf%>), or 2) use
"Response.Write" statements to write out the text.

So, for my needs, I'll probably just stick with my original
workaround:

==========================================
<% Option Explicit

Const STRING_1 = "/admin/UploadProgress2.asp"
Const STRING_A = "AXFFile" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<%=STRING_A%>.Server =
"<%=Request.ServerVariables("SERVER_NAME")%>"
<%=STRING_A%>.Port =
<%=Request.ServerVariables("SERVER_PORT")%><%=vbcrlf%>
<%=STRING_A%>.ObjectName = "<%=STRING_1%>"
</body>
</html>
==========================================



-= Tek Boy =-
 

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,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top