HtmlEncode not working? Or am I missing something

D

David Lozzi

Howdy,

I have my left navigation of Hyperlinks, and part of the link's querystring
is the title of the page they are going to. For example, one of the pages is
Cars & Trucks. With HtmlEncode, it translates it to Cars%20&%20Trucks. The
ampersand is still there. Shouldn't the HtmlEncode translate that? So on the
page the title is Cars because its translating the & as a new name/value
pair. Any suggestions?

Thanks!
 
M

Mark Fitzpatrick

David,
Are you sure you're using HtmlEncode? The text output you show is
what you would expect from a UrlEncode. HtmlEncode wouldn't convert a space
into a %20, but it would convert the & into an &. UrlEncode would do the
exact opposite and change the spaces into %20 but leave the & alone.

If you're pulling the title phrase out of the querystring you'll
need to use the UrlDecode method to get the data, such as
UrlDecode(Request.Querystring["title"].ToString());

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
 
D

David Lozzi

In my Datalist

&nbsp;-<a
href="products.aspx?DEPT=<%#Eval("ID")%>&NAME=<%#Server.HtmlEncode(Eval("Text"))%>"><%#Eval("Text")%></a>


--
David Lozzi
dlozzi@(remove)delphi-ts.com
www.delphi-ts.com


Mark Fitzpatrick said:
David,
Are you sure you're using HtmlEncode? The text output you show is
what you would expect from a UrlEncode. HtmlEncode wouldn't convert a
space into a %20, but it would convert the & into an &amp;. UrlEncode
would do the exact opposite and change the spaces into %20 but leave the &
alone.

If you're pulling the title phrase out of the querystring you'll
need to use the UrlDecode method to get the data, such as
UrlDecode(Request.Querystring["title"].ToString());

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
David Lozzi said:
Howdy,

I have my left navigation of Hyperlinks, and part of the link's
querystring is the title of the page they are going to. For example, one
of the pages is Cars & Trucks. With HtmlEncode, it translates it to
Cars%20&%20Trucks. The ampersand is still there. Shouldn't the HtmlEncode
translate that? So on the page the title is Cars because its translating
the & as a new name/value pair. Any suggestions?

Thanks!
 
M

Mark Fitzpatrick

You need to use UrlEncode to get something that you can pass in a URL, not
HtmlEncode. Then use UrlDecode to get the data.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

David Lozzi said:
In my Datalist

&nbsp;-<a
href="products.aspx?DEPT=<%#Eval("ID")%>&NAME=<%#Server.HtmlEncode(Eval("Text"))%>"><%#Eval("Text")%></a>


--
David Lozzi
dlozzi@(remove)delphi-ts.com
www.delphi-ts.com


Mark Fitzpatrick said:
David,
Are you sure you're using HtmlEncode? The text output you show is
what you would expect from a UrlEncode. HtmlEncode wouldn't convert a
space into a %20, but it would convert the & into an &amp;. UrlEncode
would do the exact opposite and change the spaces into %20 but leave the
& alone.

If you're pulling the title phrase out of the querystring you'll
need to use the UrlDecode method to get the data, such as
UrlDecode(Request.Querystring["title"].ToString());

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
David Lozzi said:
Howdy,

I have my left navigation of Hyperlinks, and part of the link's
querystring is the title of the page they are going to. For example, one
of the pages is Cars & Trucks. With HtmlEncode, it translates it to
Cars%20&%20Trucks. The ampersand is still there. Shouldn't the
HtmlEncode translate that? So on the page the title is Cars because its
translating the & as a new name/value pair. Any suggestions?

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top