HtmlTextWriter Re-encoding my strings

R

rwoodruf

Hello All,

I am using an HtmlTextWriter to writer out some html. Prior to sending the
content to the text writer, HttpUtility.HtmlEncode the string. However, doing
so results in a string where "&" become "&amp;" and "<" becomes "<".

This is a problem because I am trying to actually write out html. Does
anyone know how I can solve this problem.

For example

HttpUtility.HtmlEncode("&Attributes");

gives

"&&Attributes"

after being written out by the HtmlTextWriter. The initial encoding results
in "&Attributes". I just want it to be written out as "&Attributes".
Decoding does something even weirder :)

Thanks for your help.
 
G

George Ter-Saakov

Why do you use HtpUtility.HtmlEncode then??
Just do not use it when you outputing HTML


George
 
R

rwoodruf

It seems that the HtmlTextWriter is automatically encoding the strings
because without the HttpUtility.HtmlEncode, the following:

"&Attributes"

becomes

"&amp;Attributes"

So, any help is appreciated. It looks like the HtmlTextWriter automatically
Html Encode's all strings.

-- Rodney
 
B

bruce barker

"&"'s are only legal inside a CDATA, thats why they are automatically encoded
by the text writer.

-- bruce (sqlwork.com)
 

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,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top