473,324 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

"&" In QueryString

A link has the following URL:

<a href="Page1.asp?cname=<%= Request.QueryString("cname") %>&cadd1=<%=
Request.QueryString("cadd1") %>&cadd2=<%= Request.QueryString("cadd2")
%>&cplace=<%= Request.QueryString("cplace") %>">Click</a>

Suppose the names in the above querystring have the following values:

cname="Danny"
cadd1="House 97"
cadd2="Sector 3 & 4"
cplace="Timbaktoo"

Becuase of the presence of an ampersand (&) in the value of cadd2 (between 3
and 4), the next page doesn't get the correct querystring. The querystring
carried forward to the next page looks something like this:

Page1.asp?cname=Danny&cadd1=House%2097&cadd2=Secto r 3

That's it!!! Now how do I ensure that the presence of ampersand in any value
of the querystring doesn't affect the querystring in any way & the next page
gets the correct querystring? I even tried using Server.URLEncode but that
didn't make any difference.

Thanks,

Arpan
Jul 19 '05 #1
3 17259
An easy way is to replace it with anything then replace that thing with it
again when you receive it.

For example:

<%
cadd2 = Replace(cadd2, "&", "zxc")
%>
<a href=page1.asp?cadd2=<%=cadd2%>&...>Click</a>

When you receive it,

<%
cadd2 = Replace(Request.QueryString("cadd2"), "zxc", "&")
%>

Mohamed

"Arpan" <ar******@hotmail.com> wrote in message
news:up**************@TK2MSFTNGP12.phx.gbl...
A link has the following URL:

<a href="Page1.asp?cname=<%= Request.QueryString("cname") %>&cadd1=<%=
Request.QueryString("cadd1") %>&cadd2=<%= Request.QueryString("cadd2")
%>&cplace=<%= Request.QueryString("cplace") %>">Click</a>

Suppose the names in the above querystring have the following values:

cname="Danny"
cadd1="House 97"
cadd2="Sector 3 & 4"
cplace="Timbaktoo"

Becuase of the presence of an ampersand (&) in the value of cadd2 (between 3 and 4), the next page doesn't get the correct querystring. The querystring
carried forward to the next page looks something like this:

Page1.asp?cname=Danny&cadd1=House%2097&cadd2=Secto r 3

That's it!!! Now how do I ensure that the presence of ampersand in any value of the querystring doesn't affect the querystring in any way & the next page gets the correct querystring? I even tried using Server.URLEncode but that
didn't make any difference.

Thanks,

Arpan

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.525 / Virus Database: 322 - Release Date: 10/9/2003
Jul 19 '05 #2
> gets the correct querystring? I even tried using Server.URLEncode but that
didn't make any difference.


Can you show the code you used, and how it "didn't make any difference"?
Server.URLEncode should encode your spaces and special characters so that
they are passed correctly in the URL and are fully recoverable by the
receiving page.
Jul 19 '05 #3
Thanks Aaron. Actually I had to re-model the application where in a user
clicks a link in Page1.asp (href of the link along with the entire
querystring being the same as what I had provided in my first question). Due
to some reasons, I am assigning the href of the link in Page1.asp using
JavaScript (though it could have been done using ASP as well). Assume that
clicking this link takes the user to Page2.asp. In the JavaScript code in
Page1.asp (which directs the user to Page2.asp), I have used the function
decodeURI so that the ampersand existing within a value in the querystring
gets passed on to Page2.asp. As expected, Page2.asp gets the querystring in
the correct format. The querystring looks something like this:

?cname=Danny&cadd1=House 97&cadd2=Sector 3 & 4&cplace=Timbaktoo

Page2.asp has another link, clicking which the user is taken back to
Page1.asp along with the entire querystring. This is the code which creates
the link (note that I have encompassed the value of cadd2 in
Server.URLEncode()):

<a href="Page1.asp?cname=<%= Request.QueryString("cname") %>&cadd1=<%=
Request.QueryString("cadd1") %>&cadd2=<%=
Server.URLEncode(Request.QueryString("cadd2") %>&cplace=<%=
Request.QueryString("cplace") %>

But when the user goes back to Page1.asp, the querystring in Page1.asp looks
like this:

?cname=Danny&cadd1=House+97&cadd2=Sector+3+&cplace =Timbaktoo

Please note that in the value of cadd2, the characters "& 4" have been
neglected. I hope I have taken the right approach. Could you please try to
sort out this problem?

Thanks,

Regards,

Arpan
"Aaron Bertrand [MVP]" <aa***@TRASHaspfaq.com> wrote in message
news:uQ*************@TK2MSFTNGP11.phx.gbl...
gets the correct querystring? I even tried using Server.URLEncode but that didn't make any difference.


Can you show the code you used, and how it "didn't make any difference"?
Server.URLEncode should encode your spaces and special characters so that
they are passed correctly in the URL and are fully recoverable by the
receiving page.

Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: barney | last post by:
Hello, I' m using .NET System.Xml.XmlDOcument. When I do the following: XmlDocument xml = new XmlDocument(); xml.Load("blah"); .... xml.Save("blub"); I've got the problem that the following...
0
by: Martin Maurer | last post by:
Hello, i have a problem with NameValueCollection.Add or better with converting to a QueryString: NameValueCollection myQueryStringCollection = new NameValueCollection();...
5
by: martin | last post by:
Hi, I would be extremly grateful for some help on producing an xml fragemt. The fragment that I wish to produce should look like this <Addresses> <Address>&qout;Somebody's Name&quot;...
2
by: Mehdi | last post by:
Hi, I need to pass an URL via a hidden value as follow: <input type="hidden" id="Test" runat="Server"> and on Page_Load I assign a value to this hidden input as follow: Test.Value =...
5
by: chortler | last post by:
When I use the meta tag to refreh my asp webpage, it doesn't change Ispostback to false; It always equals true? Any ideas??
2
by: beachboy | last post by:
I have a problem if the parameter has a "&" symbol in querystring, i think asp.net will split the value into 2 values as "&" is a spliter any advise can give me to solve this problem? P.S. I...
1
by: EoRaptor013 | last post by:
Not sure where to ask this question, but... I'm using a TreeView component to enable browsing file folders in a specific directory (for test purposes /Program Files/). Some users use an ampersand...
3
by: Tanmaya Kulkarni | last post by:
Hi, I need to pass a string having ampersand "&" in the query string like Company=Johnson&Johnson. How do I send it and receive it? TIA, Tanmaya
2
by: Me | last post by:
I am passing on the input name to my asp page using Response.redirect "mypage.asp?name=" & name and the resulting url looks like 'companyname/mypage.asp?name=" & name I would like it to appear...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.