How do I stop the framework from HTML escaping my text?

A

Alan Silver

Hello,

I am populating a drop down list at run time, and the text going in
includes a pound sign. I have been trying to add the item like this...

drpFerret.Items.Add(new ListItem("Ferrets £9.99"));

but the framework HTML encodes this, resulting in the "£" being
sent out as "£" which does not display how I want.

Any ideas? TIA
 
Q

Q. John Chen

How about this:

drpFerret.Items.Add(new ListItem("Ferrets #9.99"));

and the framework should take care of the encoding.
 
A

Alan Silver

Q. said:
How about this:

drpFerret.Items.Add(new ListItem("Ferrets #9.99"));

and the framework should take care of the encoding.

How will that help? I want a pound sign, not a # sign.
 
B

Bob Barrows [MVP]

Alan said:
Hello,

I am populating a drop down list at run time, and the text going in
includes a pound sign. I have been trying to add the item like this...

drpFerret.Items.Add(new ListItem("Ferrets £9.99"));

but the framework HTML encodes this, resulting in the "£" being
sent out as "£" which does not display how I want.
How about

drpFerret.Items.Add(new ListItem("Ferrets " & Chr(156) & "9.99"));
 
A

Alan Silver

"Bob Barrows [MVP]" said:
How about

drpFerret.Items.Add(new ListItem("Ferrets " & Chr(156) & "9.99"));

Huh? That shows up as a little square box. Were you thinking of
chr(163), which is the ASCII code for the pound sign? If so, then this
doesn't answer my question as I want the HTML entity code for a pound
sign, so that people who don't necessarily have a UK language set up
will also see a pound sign. Putting the pound sign in as a character is
fine for UK people, but not for the rest of the world.

What I want is to end up with "Ferret £9.99"

Thanks anyway, any other ideas?
 
B

Bob Barrows [MVP]

Alan said:
Huh? That shows up as a little square box. Were you thinking of
chr(163), which is the ASCII code for the pound sign?

Oops, yes I was ... how did that happen?
If so, then this
doesn't answer my question as I want the HTML entity code for a pound
sign, so that people who don't necessarily have a UK language set up
will also see a pound sign. Putting the pound sign in as a character
is fine for UK people, but not for the rest of the world.

What I want is to end up with "Ferret £9.99"

Thanks anyway, any other ideas?

I don't get it. Why doesn't this work for you? Here's what I get when I
try it:

<option value="Ferrets £9.99">Ferrets £9.99</option>

Is "&pound;" so different from "£"? "&pound;" is just the named
(aliased) version of
"£" isn't it?
 
A

Alan Silver

"Bob Barrows [MVP]" said:
I don't get it. Why doesn't this work for you?

I just realised what you were trying to do, and I further realised that
the way I tried it wasn't doing the same thing!! I am using C# not VB,
so I converted your chr(163) into the wrong C# equivalent. Once I
realised what you meant, I was able to do it.

Thanks very much. Sorry for missing the point <g>
 

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,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top