469,647 Members | 1,719 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,647 developers. It's quick & easy.

Query parameters, Javascript and URL decoding issue

I am having an interesting and rather frustrating issue with the
encoding/decoding of parameters with the ASP.NET runtime. What I am
doing isn't exactly revolutionary so hopefully someone has an answer
for this.

I have a page that accepts a number of parameters. Those parameters may
sometimes include URL reserved characters like spaces and ampersands. I
use a combination of HTML and URL encoding to build links to this page
and everything works fine. No rocket science there. When however I open
a new window via javascript, the runtime seems to act unpredicatbly and
misdecode characters, namely %26, the URL encoded ampersand. For
example, the following URL in this case would work like a charm as part
of an href attribute:

mypage.aspx?t=Home%20%26%20Entertaining&c=Home &p=true

You would get three parameter values: "Home & Entertaining", "Home",
and "true". Writing out the Request.Url in the debugger gives the
following absolute URL:


When that same URL is written into javascript like so:

String.Format("javascript:windowPop('mypage.aspx?t ={0}&c={1}&p=true','',515,600,'no','no','y es')",
Server.UrlEncode(title.Replace("'","\\'")).Replace ("+", "%20"),
Server.UrlEncode(category.Replace("'","\\'")).Repl ace("+", "%20"));

*Note that windowPop is just a wrapper for
window.open(url,name,properties) and isn't important. The extra replace
functions are to escape apostrophes properly for c# and Javascript and
get real space encoding %20 instead of the IE specific plus character
UrlEncoding uses. (Causes the URL not to be found in Mozilla based

You get four query parameter values: "Home ", " Entertaining", "Home",
and "true". And writing out the absolute URL in the debugger via "?
Request.Url" gives you the following bad URL:


As you can see the URL encoding for all but the ampersand in the t
parameter is intact.

Anything that can shed light on this behavior would be greatly

Dec 22 '05 #1
0 1811

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Mark | last post: by
1 post views Thread by MattB | last post: by
10 posts views Thread by mistral | last post: by
25 posts views Thread by marcin.rzeznicki | last post: by
6 posts views Thread by sunil | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.