By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,319 Members | 2,361 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,319 IT Pros & Developers. It's quick & easy.

encoding of "&" vs "&" in url

P: n/a
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
Share this Question
Share on Google+
7 Replies


P: n/a

"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

P: n/a
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

P: n/a
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

P: n/a

"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

P: n/a
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

P: n/a
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

P: n/a

"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.