devxlogo

Using URLEncode to Pass Query String Values

Using URLEncode to Pass Query String Values

Question:
I’m passing a string from one ASP template to another. The string may contain spaces so I call URLEncode, which works well as far as preventing the 400 Error for a malformed page. However, when I encode the Query String, it seems to muck up the code that gets the values from the Query String. Is there a “decode” function that I need to use?

Answer:

When you are passing values in a Query String, you are building a string that looks like this:

page name.asp?key1=value1&key2=value2

Remember to URLEncode only the value1 and value2 strings. Do not URLEncode the key1 and key2 strings. So your code should look like this:

"key1=" & Server.URLEncode("value1") & "&key2=" & Server.UrlEncode("value2")

This code will pass the proper “value1” and “value2” even if they contain spaces or punctuation characters.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist