473,883 Members | 1,635 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"&" In QueryString

A link has the following URL:

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

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

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

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=Ho use%2097&cadd2= Sector 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.URLEncod e but that
didn't make any difference.

Thanks,

Arpan
Jul 19 '05 #1
3 17294
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("c add2"), "zxc", "&")
%>

Mohamed

"Arpan" <ar******@hotma il.com> wrote in message
news:up******** ******@TK2MSFTN GP12.phx.gbl...
A link has the following URL:

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

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

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

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=Ho use%2097&cadd2= Sector 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.URLEncod e 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.URLEncod e but that
didn't make any difference.


Can you show the code you used, and how it "didn't make any difference"?
Server.URLEncod e 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&ca dd1=House 97&cadd2=Secto r 3 & 4&cplace=Timbak too

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.URLEncod e()):

<a href="Page1.asp ?cname=<%= Request.QuerySt ring("cname") %>&cadd1=<%=
Request.QuerySt ring("cadd1") %>&cadd2=<%=
Server.URLEncod e(Request.Query String("cadd2") %>&cplace=<%=
Request.QuerySt ring("cplace") %>

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

?cname=Danny&ca dd1=House+97&ca dd2=Sector+3+&c place=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***@TRASHasp faq.com> wrote in message
news:uQ******** *****@TK2MSFTNG P11.phx.gbl...
gets the correct querystring? I even tried using Server.URLEncod e but that didn't make any difference.


Can you show the code you used, and how it "didn't make any difference"?
Server.URLEncod e 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
14824
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 expression: .... snip ...
0
1103
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(); myQueryStringCollection.Add("Test1", null); myQueryStringCollection.Add("Test2","abc"); WebClient myWebClient = new WebClient(); myWebClient.QueryString = myQueryStringCollection;
5
3450
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; &lt;me@mydomain.com&gt;</Address> </Addresses>
2
1630
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 = "http://www.myserver.com?id=123&name=HomerSimpson";
5
2298
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
2561
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 can't restrict user don't input "&" symbol when input Thanks in advanced.
1
2944
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 ("&") in both folder and file names. This has caused me some real grief! I'm not in a position to tell the users it's an ID 10 T error and they have to change their file and folder names. In VS2K5, I have debugged my code and found that ...
3
1546
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
2077
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 like 'companyname' or at most 'companyname/mypage.asp' how can I do it?
0
9933
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9779
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10407
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9563
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7960
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7114
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5982
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4205
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.