HtmlTextWriter Re-encoding my strings

  • Thread starter Thread starter rwoodruf
  • Start date Start date
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.
 
Why do you use HtpUtility.HtmlEncode then??
Just do not use it when you outputing HTML


George
 
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
 
"&"'s are only legal inside a CDATA, thats why they are automatically encoded
by the text writer.

-- bruce (sqlwork.com)
 
Back
Top