473,408 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

HtmlTextWriter Re-encoding my strings

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.
Feb 4 '08 #1
3 5319
Why do you use HtpUtility.HtmlEncode then??
Just do not use it when you outputing HTML
George
"rwoodruf" <rw******@discussions.microsoft.comwrote in message
news:D5**********************************@microsof t.com...
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.

Feb 4 '08 #2
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

"George Ter-Saakov" wrote:
Why do you use HtpUtility.HtmlEncode then??
Just do not use it when you outputing HTML
George
"rwoodruf" <rw******@discussions.microsoft.comwrote in message
news:D5**********************************@microsof t.com...
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 "&" 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.


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

-- bruce (sqlwork.com)
"rwoodruf" wrote:
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 "&" 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.
Feb 4 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Blaz Ziherl | last post by:
Hi, I am developing an application in VisualBasic .NET and got the following error: "An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll ...
1
by: Rudy Ko | last post by:
Hi, All: I'm populating database records into a panel controls and want to render that panel into a HtmlTextWriter which will creating a word document. Do you know how to insert a page break...
1
by: Tammy | last post by:
I am fairly new to asp and web development. I'm having a tough time with the htmltextwriter. I keep receiving an error that basically says 'object reference not set to instance of object. It sure...
1
by: Mike | last post by:
I write many custom controls and think that the HtmlTextWriter would benefit from a method such as: writer.Write("<td>{0}<td>", new HtmlTextWriterCallback(this.WriteCell)) void...
3
by: Lee Chapman | last post by:
Hi, I want my ASP.NET web application to use a custom HtmlTextWriter. i.e. I want the object that the Framework passes to System.Web.UI.Control.Render() to be my own object, MyHtmlTextWriter,...
2
by: Larry Van | last post by:
I have been beating my head against a wall for two days now. I have developed a treeview control that reads in an xml file which holds the information for building the tree. The nodes are...
4
by: James Page | last post by:
I can't seem to get HtmlTextWriter / renderControl to work for sending a control (html) in an e-mail messsage (VB.NET). Keeps telling me that control needs to be in a form tag with runat server...
0
by: John Walker | last post by:
Hi, I have an asp.net application which binds a dataview to a datagrid, which then renders control to an HtmlTextWriter and then by doing a "response.write" my datagrid is successfully displayed...
2
by: rodchar | last post by:
hey all, can someone please show me how to write this to a stringbuilder using the htmltextwriter: <ul><li>test</li></ul> thanks, rodchar
0
by: dihola | last post by:
Hi all, A component I have renders itself (essentially an HTML table) using an HtmlTextWriter object to create some HTML code. This component is part of an aspx page. I need the component to also...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.