473,387 Members | 1,416 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,387 software developers and data experts.

how to properly encode ampersands in querystring

I am creating a querystring to look like this:

form_edit.aspx?collectionID=25&confirmationMes sage=New+form+entry+saved

Note that I'm escaping the ampersand.

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

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

Or maybe Server.HTMLEncode and Server.HTMLDecode?
http://www.devx.com/tips/Tip/13459

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

form_edit.aspx?collectionID=25&amp;confirmationMes sage=New+form+entry+saved

Note that I'm escaping the ampersand.

However, I can't grab the 'confirmationMessage' 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.URLEncode?
http://www.4guysfromrolla.com/webtech/042601-1.shtml

Or maybe Server.HTMLEncode and Server.HTMLDecode?
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 NameValueCollection
nvc=Request.QueryString
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*****@hotmail.com> wrote in message
news:Oy**************@TK2MSFTNGP15.phx.gbl...
Are you looking for Server.URLEncode?
http://www.4guysfromrolla.com/webtech/042601-1.shtml

Or maybe Server.HTMLEncode and Server.HTMLDecode?
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;confirmationMes sage=New+form+entry+
saved

Note that I'm escaping the ampersand.

However, I can't grab the 'confirmationMessage' 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;&confirmationMe ssage=New+....

I hope it helps to encode/decode.

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

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

Note that I'm escaping the ampersand.

However, I can't grab the 'confirmationMessage' 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">Link</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;&confirmationMe ssage=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 is valid XHTML (and works just fine):

<a href="http://myserver/mypage.aspx?a=1&amp;b=2">Link</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.


Ah! Perhaps that's my problem. I'm not creating an href link, but rather,
I'm using response.redirect

-Darrel
Nov 19 '05 #11
A URL is not HTML or XHTML. It is a URL. I was speaking in the context of a
URL, not the HTML document itself. When a URL is inside an HTML document (in
a link, for example), it needs to be HTML-Encoded. Otherwise not. See
http://www.gbiv.com/protocols/uri/rfc/rfc3986.html

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"darrel" <no*****@hotmail.com> wrote in message
news:u9**************@TK2MSFTNGP09.phx.gbl...
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 #12
> a link, for example), it needs to be HTML-Encoded. Otherwise not. See
http://www.gbiv.com/protocols/uri/rfc/rfc3986.html


OH! I think this clarifies things. So, if it's a URL in my codebehind (as a
response.redirect) encoding is rather pointless?

-Darrel
Nov 19 '05 #13
darrel wrote:
Ah! Perhaps that's my problem. I'm not creating an href link, but
rather, I'm using response.redirect


Right, in that case, you don't want to encode ampersands when you're using
them as value separators.

You'd only encode them in a Response.Redirect if they actually formed part
of one of the values, as detailed somewhere else on this thread.

--

(O) e n o n e
Nov 19 '05 #14

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

Similar topics

2
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. ...
1
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...
2
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...
5
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 &...
2
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...
3
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...
4
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....
3
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=" &...
2
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" ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...

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.