views:

289

answers:

2

I am using the following code to add a series of calls to the body parameter of a page in asp.net:

uxBodyTag.Attributes["onbeforeunload"] += 
  "ajaxRequest('UnlockQuery.ashx?QueryID=" + queryId.ToString() + 
  "&UserID=" + Session["UserID"].ToString() + "');";

This is being rendered as:

<body id="uxBodyTag" onbeforeunload=
    "ajaxRequest('UnlockQuery.ashx?QueryID=176&amp;UserID=11648');">

The &amp; means my ashx page is not retrieving the correct variables - how can I stop asp.net from doing this?

EDIT:

Using Server.UrlEncode gives me the following:

<body id="uxBodyTag" onbeforeunload=
 "ajaxRequest('UnlockQuery.ashx%3fQueryID%3d179%26UserID%3d11648')%3b">

Which is far worse.

+2  A: 

The behaviour you are seeing with & encoded as &amp; is the behaviour you want. By the time the text gets to your ajaxRequest function it will have been unencoded again and everything should be fine.

andynormancx
I'll check that - it seems I may have another issue at the moment, and this was the most obvious likely cause
ck
A simple test is just to replace ajaxRequest with alert, you'll then see that your URL and query string is intact.
andynormancx
+4  A: 
Tomalak