468,507 Members | 1,487 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,507 developers. It's quick & easy.

encoding of "&" vs "&" in url

I am having a bear of a time with setting a URL query string as a text value
in a dropdownlist and Server.URLEncode does not seem to do its job.

theFullLink = theLinkPrefix & theImageryTypeTrimmed &
Server.URLEncode("&f=")
ddlMyDropDownList.Items.Add(New ListItem("MyTextValue", theFullLink & "af"))

Which puts out the following HTML:

<option value="~/folder/page.aspx?param1=value1%26f%3daf">-
Afghanistan</option>

If I leave off the Server.URLEncode() i get:

<option value="~/folder/page.aspx?param1=value1&amp;f=af">-
Afghanistan</option>

Help!

_____
DC G
Nov 19 '05 #1
7 2524

"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:OC**************@TK2MSFTNGP12.phx.gbl...
If I leave off the Server.URLEncode() i get:

<option value="~/folder/page.aspx?param1=value1&amp;f=af">-
Afghanistan</option>

Help!


This output seems correct to me. What were you expecting?

- Oliver
Nov 19 '05 #2
I was expecting:

<option value="~/folder/page.aspx?param1=value1&f=af">- Afghanistan</option>

This dropdownlist is being posted back and it does not work as is...
____
DC G
"Oliver Wong" <ow***@castortech.com> wrote in message
news:cuuIe.207802$on1.77081@clgrps13...

"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:OC**************@TK2MSFTNGP12.phx.gbl...
If I leave off the Server.URLEncode() i get:

<option value="~/folder/page.aspx?param1=value1&amp;f=af">-
Afghanistan</option>

Help!


This output seems correct to me. What were you expecting?

- Oliver

Nov 19 '05 #3
Try passing the character entity & instead of the ampersand.

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/
"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:Ob**************@TK2MSFTNGP14.phx.gbl...
I was expecting:

<option value="~/folder/page.aspx?param1=value1&f=af">-
Afghanistan</option>

This dropdownlist is being posted back and it does not work as is...
____
DC G
"Oliver Wong" <ow***@castortech.com> wrote in message
news:cuuIe.207802$on1.77081@clgrps13...

"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:OC**************@TK2MSFTNGP12.phx.gbl...
If I leave off the Server.URLEncode() i get:

<option value="~/folder/page.aspx?param1=value1&amp;f=af">-
Afghanistan</option>

Help!


This output seems correct to me. What were you expecting?

- Oliver


Nov 19 '05 #4

"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:Ob**************@TK2MSFTNGP14.phx.gbl...
I was expecting:

<option value="~/folder/page.aspx?param1=value1&f=af">-
Afghanistan</option>

This dropdownlist is being posted back and it does not work as is...


Unfortunately, I don't think the above is legal XML (and therefor not
valid XHTML either). The ampersign means that the next few characters will
refer to an entity reference, but entity references are always terminsated
by a semicolon, and there is no semicolon after the ampersign. I'm assuming
you want the "value" attribute to have the following value:
"~/folder/page.aspx?param1=value1&f=af". To express that in XML, you'd have
to escape the ampersign so that what actually appears in the XML file is
"~/folder/page.aspx?param1=value1&amp;f=af".

This is similar to the concept that to represent the string which only
contains one instance of the character \, you have to type it in as "\\" or
@"\" in C#.

- Oliver
Nov 19 '05 #5
Clinton,

Thanks for the suggestion, but it didn't work...the result was:

<option value="~/centers/innerSections.aspx?pageID=ndvi&amp;#38;f=af">-
Afghanistan</option>

_____
DC G

"clintonG" <cs*********@REMOVETHISTEXTmetromilwaukee.com> wrote in message
news:OL**************@tk2msftngp13.phx.gbl...
Try passing the character entity & instead of the ampersand.

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/
"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:Ob**************@TK2MSFTNGP14.phx.gbl...
I was expecting:

<option value="~/folder/page.aspx?param1=value1&f=af">-
Afghanistan</option>

This dropdownlist is being posted back and it does not work as is...
____
DC G
"Oliver Wong" <ow***@castortech.com> wrote in message
news:cuuIe.207802$on1.77081@clgrps13...

"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:OC**************@TK2MSFTNGP12.phx.gbl...
If I leave off the Server.URLEncode() i get:

<option value="~/folder/page.aspx?param1=value1&amp;f=af">-
Afghanistan</option>

Help!

This output seems correct to me. What were you expecting?

- Oliver



Nov 19 '05 #6
Oliver,

Thank you for the explanation...that seems to make good sense.

However, I still have to implement this code somehow. How else can I do
this?

theFullLink = theLinkPrefix & theImageryTypeTrimmed & "&f="
ddlGotoRegionCountryCenter.Items.Add(New ListItem("- countryName",
theFullLink & "af"))

To get this output:

<option value="~/folder/page.aspx?param1=value1&f=af">- countryName</option>

???
_____
DC G

"Oliver Wong" <ow***@castortech.com> wrote in message
news:x_KIe.158904$HI.81946@edtnps84...

"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:Ob**************@TK2MSFTNGP14.phx.gbl...
I was expecting:

<option value="~/folder/page.aspx?param1=value1&f=af">-
Afghanistan</option>

This dropdownlist is being posted back and it does not work as is...


Unfortunately, I don't think the above is legal XML (and therefor not
valid XHTML either). The ampersign means that the next few characters will
refer to an entity reference, but entity references are always terminsated
by a semicolon, and there is no semicolon after the ampersign. I'm
assuming you want the "value" attribute to have the following value:
"~/folder/page.aspx?param1=value1&f=af". To express that in XML, you'd
have to escape the ampersign so that what actually appears in the XML file
is "~/folder/page.aspx?param1=value1&amp;f=af".

This is similar to the concept that to represent the string which only
contains one instance of the character \, you have to type it in as "\\"
or @"\" in C#.

- Oliver

Nov 19 '05 #7

"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:OB****************@TK2MSFTNGP12.phx.gbl...
Oliver,

Thank you for the explanation...that seems to make good sense.

However, I still have to implement this code somehow. How else can I do
this?


The point I'm getting at is that the text you're trying to output isn't
valid XML, so assuming you want to output XML (e.g. HTML), you should never
need to put an ampersign like that.

However, if for some reasons, you have clients or something which demand
this kind of output, then try emitting the data as plain text instead of
HTML; that way, you won't have any sort of escaping mechanism interfering.

- Oliver
Nov 19 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by barney | last post: by
5 posts views Thread by martin | last post: by
3 posts views Thread by DC Gringo | last post: by
7 posts views Thread by DC Gringo | last post: by
3 posts views Thread by beachboy | last post: by
14 posts views Thread by Arne | last post: by
2 posts views Thread by imonline | last post: by
12 posts views Thread by Michel Vanderbeke | last post: by
reply views Thread by bruce | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.