Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

handling special characters in asp 2

Status
Not open for further replies.

sweetleaf

Programmer
Jan 16, 2001
439
CA
hi,

Does anyone have any idea as to what might be causing the following:

I have a hyperlink which reoloads an asp with querystrings
x,y,z.

x,y and z load values like C1,VR,7T into correlating text boxes.

Everything works fine except when x,y or z contains values with special characters like C#,B+ or #I..

Does anyone know what I can do to alleviate this?

Any help sure would be appreciated a lot!
 
The reason that you are having a problem is because url's cannot contain those characters. You may notice when you have a space in a url it changes it to %20. There is a function ASP to convert a string to a valid url, Server.URLEncode(str) will encode the special characters in str to be ok.
-tarwn
 
Hi guys,

thanks for all your input - but I've tried (sorry forgot to mention) server.urlencode and server.htmlencode already and still i'm having this problem - don't know why..
 
heres the link on my page which reloads the page with querystring values:

<a href=&quot;service.asp?z=<% server.urlencode(Response.write(rst(&quot;SERVICE_CD&quot;)))%> &x=<% Response.write(rst(&quot;DESC1&quot;))%> &y=<% Response.write(rst(&quot;DESC2&quot;))%> &aa=<% Response.write(rst(&quot;DESC3&quot;))%>&quot;>Edit</a>

.. the querystring &quot;z&quot; uses urlencode (i've also tried htmlencode).

thanks guys and gals
 
<a href=&quot;service.asp?z=<% server.urlencode(rst(&quot;SERVICE_CD&quot;))%> &x=<% Response.write(rst(&quot;DESC1&quot;))%> &y=<% Response.write(rst(&quot;DESC2&quot;))%> &aa=<% Response.write(rst(&quot;DESC3&quot;))%>&quot;>Edit</a>
 
Ah, forget what i said above, try this:

<%

Dim Service_cd, desc1, desc2, desc3


'#put all data in a string...

Service_cd = Server.URLencode(rst(&quot;Service_CD&quot;))
desc1 = Server.URLencode(rst(&quot;DESC1&quot;))
desc2 = Server.URLencode(rst(&quot;DESC2&quot;))
desc3 = Server.URLencode(rst(&quot;DESC3&quot;))

'# NOTE: <%=&quot;An &quot;=&quot; sign is the same as using response.write&quot;%>

<a href=&quot;service.asp?z=<%=Service_cd%>&x=<%=desc1%>&y=<%=desc2%>&aa=<%=desc4%>&quot;>Edit</a>




%>
 
Thanks snowboardr!

that hit the spot!
my code works fine now - amazing!

cheers!
 
Snowboardr,

I want to try your code fix but don't quite understand what you're doing. Can you break it down for me... I'm a beginner. Thanks.

Your code read:
<%

Dim Service_cd, desc1, desc2, desc3


'#put all data in a string...

Service_cd = Server.URLencode(rst("Service_CD"))
desc1 = Server.URLencode(rst("DESC1"))
desc2 = Server.URLencode(rst("DESC2"))
desc3 = Server.URLencode(rst("DESC3"))

'# NOTE: <%="An "=" sign is the same as using response.write"%>

<a href="service.asp?z=<%=Service_cd%>&x=<%=desc1%>&y=<%=desc2%>&aa=<%=desc4%>">Edit</a>




%>
 
this might be of assistance as well in your issue :
it's just the reverse of a URLEncode, i still have yet to write a HTMLDeCode
Code:
function URLDecode(str)
	dim re
	set re = new RegExp
	str = Replace(str, "+", " ")
	re.Pattern = "%([0-9a-fA-F]{2})"
	re.Global = True
	URLDecode = re.Replace(str, GetRef("URLDecodeHex"))
end function

' Replacement function for the above
function URLDecodeHex(match, hex_digits, pos, source)
	URLDecodeHex = chr("&H" & hex_digits)
end function

[thumbsup2]DreX
aKa - Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top