Losing part of my querystring

L

LouV

Hi all. Hope someone can push me in the right direction. I'm new to
ASP.net and I am not sure how I would fix this. I've searched
newsgroups, web sites and MSDN and haven't seen how to get around
this.

I created a master datagrid with a hypertext column. Clicking on any
item in this column opens up a detail datagrid. I did this by placing
the following URL in the URL format string in the column properties
for the hypertext column in the property builder: Details.aspx?id={0}.
In Details.aspx, I read the parameter passed through the query string
using Request.QueryString("id"). I use this parameter as the input
parameter for a stored procedure that populates the detail datagrid.
The parameter is a string and it works great. But when the paramteter
has an embedded ampersand (&), the ampersand and everything after it
is not returned by the Request.QueryString("id"). For example, when
the querystring is Details.aspx?ItemA, the details for ItemA are
returned by the stored procedure and populates the datagrid. But when
the querystring is Details.aspx?ItemB&C, the database is queried for
ItemB instead of ItemB&C because the &C was dropped. When I do a
rollover on the hypertext on the master datagrid, I can see that the
URL to be executed is Details.aspx?ItemB&C. But when I step through
the code in detail.aspx, the Request.QueryString("id") returns ItemB.
So somewhere before the detail.aspx is loaded, ASP.net truncates the
string.

Does the string need to be Details.aspx?ItemB&&C for it to pick up the
ampersand? How would I do this in the URL format string in the
property builder? Or do I have to do this in code somehow? Thanks
in advance for any guidance.
 
G

Guest

The problem you are running into here is that the ampersand character "&" is a reserved character in query strings. What you need to do is URL Encode your string to get around this problem. This will automatically escape out and reserved chars you might have. For example

dim strMyItem as string = "ItemB&C

strMyItem=Server.UrlEncode(strMyItem
Session("Item") = strMyIte

Response.Redirect("http://somewhere.com?ItemID=" & Session("Item")

Hope this helps
-Cla

Clayton Gulick, MCSD
 
L

LouV

I set the url in code using UrlEncode instead of using property
builder and that did the trick. Thanks for you help Clayton.
 

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

Top