Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > how to properly encode ampersands in querystring

Reply
Thread Tools

how to properly encode ampersands in querystring

 
 
darrel
Guest
Posts: n/a
 
      06-13-2005
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


 
Reply With Quote
 
 
 
 
Steve C. Orr [MVP, MCSD]
Guest
Posts: n/a
 
      06-13-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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
>
>



 
Reply With Quote
 
 
 
 
darrel
Guest
Posts: n/a
 
      06-13-2005
> 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


 
Reply With Quote
 
Steve C. Orr [MVP, MCSD]
Guest
Posts: n/a
 
      06-13-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>> 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
>
>



 
Reply With Quote
 
tom.pesterDeLeTeTHISSS@pandora.be
Guest
Posts: n/a
 
      06-13-2005
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
>



 
Reply With Quote
 
=?Utf-8?B?UHJha2FzaC5ORVQ=?=
Guest
Posts: n/a
 
      06-14-2005
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
>
>
>

 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      06-14-2005
You're using HTML Encoding in a URL. You should use URL Encoding instead:

form_edit.aspx?collectionID=25%38confirmationMessa ge=New+form+entry+saved

OR, you should NOT encode the ampersand at all, if you're trying to send
multiple parameters:

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

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.


--
HTH,

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

"darrel" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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
>
>



 
Reply With Quote
 
Oenone
Guest
Posts: n/a
 
      06-14-2005
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


 
Reply With Quote
 
darrel
Guest
Posts: n/a
 
      06-14-2005
> 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


 
Reply With Quote
 
darrel
Guest
Posts: n/a
 
      06-14-2005
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
validating quoted ampersands mouse@house.spam HTML 4 09-24-2006 04:31 PM
c:url encoding issue with ampersands johkar Java 0 02-25-2006 05:00 PM
Naming of ampersands and other tricky characters Andy Dingley XML 1 06-10-2004 03:34 PM
Links/ampersands in HTML tags using XML/XSLT SDM XML 2 09-22-2003 02:01 PM
Ampersands being converted when in data that is bound to my ASP:Dropdown Howard, Brett ASP .Net 1 07-12-2003 06:39 AM



Advertisments