Querystrings different in straight HTML and delimited ASP

N

.Net Sports

I have querystrings that are referencing the same queried object:

HTML: <a href="?qencl=<%=qencl%>&cat=<%=qc%> ....

ASP: Response.Write "<a href=?qencl="&qencl&"&cat="&qc&"...

the queried object "cat" does not break up if the "cat" has spaces in
it on the "HTML" version

the queried object "cat" breaks off at the first space in the "ASP:
version

HTML = http://www.mysite.com/my.asp?qencl=sup&cat=Critical
Infrastructure and Key Resources

ASP: = http://www.mysite.com/my.asp?qencl=sup&cat=Critical

not sure to what extent i need to use Server.URLEncode in this snafu

???
NS
 
A

Adrienne Boswell

I have querystrings that are referencing the same queried object:

HTML: <a href="?qencl=<%=qencl%>&cat=<%=qc%> ....

ASP: Response.Write "<a href=?qencl="&qencl&"&cat="&qc&"...

the queried object "cat" does not break up if the "cat" has spaces in
it on the "HTML" version

the queried object "cat" breaks off at the first space in the "ASP:
version

HTML = http://www.mysite.com/my.asp?qencl=sup&cat=Critical
Infrastructure and Key Resources

ASP: = http://www.mysite.com/my.asp?qencl=sup&cat=Critical

not sure to what extent i need to use Server.URLEncode in this snafu

???
NS

dim q, r, t
q = 1
r = 2
t = 3

Response.Write "<a href=" & chr(34) & "somepage.asp?q=" & id &
"&amp;r=" & col & "&amp;t=" & tld & chr(34) & ">somepage</a>"

which the browser will parse as
<a href="somepage.asp?q=1&r=2&t=3">somepage</a>

The & character should be escaped &amp; except in the case of a
response.redirect or server.transfer, and the quotation marks should
remain in place. Others use double quotes, but I prefer using chr(34)
instead - it's easier to debug.
 
D

Dan

.Net Sports said:
I have querystrings that are referencing the same queried object:

HTML: <a href="?qencl=<%=qencl%>&cat=<%=qc%> ....

ASP: Response.Write "<a href=?qencl="&qencl&"&cat="&qc&"...

the queried object "cat" does not break up if the "cat" has spaces in
it on the "HTML" version

the queried object "cat" breaks off at the first space in the "ASP:
version

HTML = http://www.mysite.com/my.asp?qencl=sup&cat=Critical
Infrastructure and Key Resources

ASP: = http://www.mysite.com/my.asp?qencl=sup&cat=Critical

not sure to what extent i need to use Server.URLEncode in this snafu

???
NS


In the latter case you are not quoting the URL, which is why a space causes
a problem. You should never be using spaces in URLs though.

In both case, use Server.URLEncode to encode each value, eg.

Response.Write "<a href=""?qencl=" & Server.URLEncode(qencl) & "&cat=" &
Server.URLEncode(qc) & ... """>"


note that I've also added "" after the href=, this is one way to add double
quotes into strings in ASP VBScript; another being the Chr(34) that Adrienne
has suggested.
 

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,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top