472,793 Members | 2,199 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,793 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 17195
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.