473,549 Members | 2,584 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to properly encode ampersands in querystring

I am creating a querystring to look like this:

form_edit.aspx? collectionID=25 &confirmati onMessage=New+f orm+entry+saved

Note that I'm escaping the ampersand.

However, I can't grab the 'confirmationMe ssage' querystring unless I do NOT
encode the ampersand. I assume I'm missing something obvious here. Any
suggestions?

-Darrel
Nov 19 '05 #1
13 26422
Are you looking for Server.URLEncod e?
http://www.4guysfromrolla.com/webtech/042601-1.shtml

Or maybe Server.HTMLEnco de and Server.HTMLDeco de?
http://www.devx.com/tips/Tip/13459

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"darrel" <no*****@hotmai l.com> wrote in message
news:Ol******** ******@TK2MSFTN GP10.phx.gbl...
I am creating a querystring to look like this:

form_edit.aspx? collectionID=25 &amp;confirmati onMessage=New+f orm+entry+saved

Note that I'm escaping the ampersand.

However, I can't grab the 'confirmationMe ssage' querystring unless I do
NOT
encode the ampersand. I assume I'm missing something obvious here. Any
suggestions?

-Darrel

Nov 19 '05 #2
> Are you looking for Server.URLEncod e?
http://www.4guysfromrolla.com/webtech/042601-1.shtml

Or maybe Server.HTMLEnco de and Server.HTMLDeco de?
http://www.devx.com/tips/Tip/13459


Well, I'm 'encoding' it manually, but yea, maybe I need to unencode it.

So, how would I call a querystring in a URL after HTMLDecode?

Or would I decode it, then just parse it as a text string?

-Darrel
Nov 19 '05 #3
You could do that. Or, on the receiving page you can get the value off the
querystring with
code something like this:
Dim nvc As NameValueCollec tion
nvc=Request.Que ryString
Here's more info:

http://msdn.microsoft.com/library/de...ClassTopic.asp

---
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net

"darrel" <no*****@hotmai l.com> wrote in message
news:Oy******** ******@TK2MSFTN GP15.phx.gbl...
Are you looking for Server.URLEncod e?
http://www.4guysfromrolla.com/webtech/042601-1.shtml

Or maybe Server.HTMLEnco de and Server.HTMLDeco de?
http://www.devx.com/tips/Tip/13459


Well, I'm 'encoding' it manually, but yea, maybe I need to unencode it.

So, how would I call a querystring in a URL after HTMLDecode?

Or would I decode it, then just parse it as a text string?

-Darrel

Nov 19 '05 #4
I'm curious why do you need to encode the ampersand? Is it to comply to XHTML
standards?

Cheers,
Tom Pester
I am creating a querystring to look like this:

form_edit.aspx? collectionID=25 &amp;confirmati onMessage=New+f orm+entry+
saved

Note that I'm escaping the ampersand.

However, I can't grab the 'confirmationMe ssage' querystring unless I
do NOT encode the ampersand. I assume I'm missing something obvious
here. Any suggestions?

-Darrel

Nov 19 '05 #5
I suggest that you put one more ampersand after & because each and every
value in a query string is separated by ampersand. For example
index.aspx?a=5& b=10. In your example,
form_edit.aspx? collectionID=25 &amp;&confirmat ionMessage=New+ ....

I hope it helps to encode/decode.

"darrel" wrote:
I am creating a querystring to look like this:

form_edit.aspx? collectionID=25 &confirmationMe ssage=New+form+ entry+saved

Note that I'm escaping the ampersand.

However, I can't grab the 'confirmationMe ssage' querystring unless I do NOT
encode the ampersand. I assume I'm missing something obvious here. Any
suggestions?

-Darrel

Nov 19 '05 #6
Kevin Spencer wrote:
The ampersand is a standard URL delimiter for parameters in a query
string. It should never be HTML-Encoded.


Unless it's being included within the HTML itself (for example, in an anchor
tag), in which case it should.

This is valid XHTML (and works just fine):

<a href="http://myserver/mypage.aspx?a=1 &amp;b=2">Li nk</a>

When clicked, the actual URL that will be present in the browser will have a
plain ampersand between the two parameters, not an encoded ampersand.

This is not valid (though it also works):
<a href="http://myserver/mypage.aspx?a=1 &b=2">Link</a>

HTML can be a pain in the backside sometimes.

--

(O)enone
Nov 19 '05 #7
> I'm curious why do you need to encode the ampersand? Is it to comply to
XHTML
standards?


I don't *need* too...just trying to get in the habit of doing it.

-Darrel
Nov 19 '05 #8
> I suggest that you put one more ampersand after & because each and every
value in a query string is separated by ampersand. For example
index.aspx?a=5& b=10. In your example,
form_edit.aspx? collectionID=25 &amp;&confirmat ionMessage=New+ ....

I hope it helps to encode/decode.


The problem is that I still have an unencoded ampersand in the URL then.

-Darrel
Nov 19 '05 #9
> The ampersand is a standard URL delimiter for parameters in a query
string.
It should never be HTML-Encoded. If you want to send a literal ampersand,
you should use URL-Encoding, as per my first suggestion.


I was under the impression that an amersand in a URL, unenecoded, was
invalid XHTML.

http://www.456bereastreet.com/archiv...nd_validation/

Also, you introduce the problem of accidently creating an unintentional
entity:

mypage.aspx?id= 2&amplitude=4
----

which can mess up some browsers.

-Darrel
Nov 19 '05 #10

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

Similar topics

2
4980
by: micha | last post by:
my php script gets delivered text that contains special chars (like german umlauts), and these chars may, may partially or may not be coverted into html entities already. i don't know beforhand. question: how to spot wether an ampersand is just an ampersand and needs to be converted or is part of an html entity and must be left alone? ...
1
1348
by: Travis Pupkin | last post by:
How do you handle an ampersand (&) if it appears as part of the string in a querystring? Is there a way to tell the server it is not the beginning of a new variable being passed, but rather just a part of the string value? Thanks
2
5517
by: SDM | last post by:
I need to create a stylesheet to allow the querystring in my attribute links to format as: <TD<A href='IQNet.asp?f=2&t=3'>Choice 1</A></TD> not <TD<A href='IQNet.asp?f=2&amp;t=3'>Choice 1</A></TD> I can't put an XSLT tag inside an HTML tag so <xsl:text disable-output-escaping="yes"> won't cut it.
5
6478
by: AJ Brown | last post by:
How does one allow the use of ampersands (or other special characters for that matter) within Element text and Attribute text? I have problems using LoadXml from a string "<text value="Jack & Jill"/>" into an XmlDocument. I can't for the life of me find a switch that turns off this feature of the parser. -AJ
2
5507
by: Larry | last post by:
I am hoping there is a way to encode the querystring part of a URL reached from a hyperlink that will cause the Request to not drop the info after the # in the URL string. Any clues or links to details on how I would do this? Thanks!
3
1987
by: Dariusz Tomon | last post by:
Hi My problem is like that: I'm trying to pass values branza and jezyk in querysting: http://localhost/euroadres/pokazbranza.aspx?branza=transport lotniczy&jezyk=1 Branza is type "string" and when I'm passing string value without national
4
9476
by: | last post by:
Hi all, If I am reading this right, then the querystring parameters must be "&amp;" and not "&". However, IIS 6.0 and asp.net request.querystring fails to capture the values if "&amp;" is specified. e.g. http://myserver/test.aspx?pid=1&amp;did=2 http://www.w3.org/TR/html401/appendix/notes.html#h-B.2.2 Any ideas?
3
6653
by: Elroyskimms | last post by:
I have to encode an address which contains an ampersand (&) into a URL with various querystring parameters. The following code works fine: URLString = "www.myserver.com?AD1=" & HTTPUtility.URLEncode("500 Rt 6 & 209") and then to retrieve it: txtAddress1.text = Request.Querystring("AD1") However, in a different page of code, I loop...
2
2764
by: subbusuresh | last post by:
hi, Any one can help me. <asp:GridView ID="grvDCList" runat="server" AutoGenerateColumns="False" > <Columns> <asp:HyperLinkField HeaderText="DC Number" DataNavigateUrlFields="Code" DataNavigateUrlFormatString="Default.aspx?Code={0}" Target="_blank" DataTextField="DC_NO" NavigateUrl="#" > <ItemStyle...
0
7527
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...
0
7459
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...
0
7819
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...
0
6052
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...
1
5377
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...
0
5097
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...
0
3488
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
772
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.