473,804 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Server.HTMLEnco de

Hi,

The following is lifted straight from the MSDN help topic for
HttpServerUtili ty.HtmlEncode Method [C#]

---------------------------------------------------------------
The following example encodes a string for transmission by HTTP. It encodes
the string named TestString, which contains the text "This is a <Test
String>.", and copies it into the string named EncodedString as
"This+is+a+%3cT est+String%3e." .

[C#]
String TestString = "This is a <Test String>.";
StringWriter writer = new StringWriter();
Server.HtmlEnco de(TestString, writer);
String EncodedString = writer.ToString ();
---------------------------------------------------------------

However, when I run it, the value of EncodedString is "This is a &lt;Test
String&gt;." not "This+is+a+%3cT est+String%3e."

Am I missing something? Am I not using the correct encoding method?

Any assistance gratefully received.

Best,

Mark Rae
Nov 18 '05 #1
3 5752
Hi,

Use Server.UrlEncod e for the output you are expecting.

"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:eB******** *****@TK2MSFTNG P11.phx.gbl...
Hi,

The following is lifted straight from the MSDN help topic for
HttpServerUtili ty.HtmlEncode Method [C#]

---------------------------------------------------------------
The following example encodes a string for transmission by HTTP. It encodes
the string named TestString, which contains the text "This is a <Test
String>.", and copies it into the string named EncodedString as
"This+is+a+%3cT est+String%3e." .

[C#]
String TestString = "This is a <Test String>.";
StringWriter writer = new StringWriter();
Server.HtmlEnco de(TestString, writer);
String EncodedString = writer.ToString ();
---------------------------------------------------------------

However, when I run it, the value of EncodedString is "This is a &lt;Test
String&gt;." not "This+is+a+%3cT est+String%3e."

Am I missing something? Am I not using the correct encoding method?

Any assistance gratefully received.

Best,

Mark Rae

Nov 18 '05 #2
Mark Rae wrote:
Hi,

The following is lifted straight from the MSDN help topic for
HttpServerUtili ty.HtmlEncode Method [C#]

---------------------------------------------------------------
The following example encodes a string for transmission by HTTP. It encodes
the string named TestString, which contains the text "This is a <Test
String>.", and copies it into the string named EncodedString as
"This+is+a+%3cT est+String%3e." .

[C#]
String TestString = "This is a <Test String>.";
StringWriter writer = new StringWriter();
Server.HtmlEnco de(TestString, writer);
String EncodedString = writer.ToString ();
---------------------------------------------------------------

However, when I run it, the value of EncodedString is "This is a &lt;Test
String&gt;." not "This+is+a+%3cT est+String%3e."

Am I missing something? Am I not using the correct encoding method?

Any assistance gratefully received.

Best,

Mark Rae


Try Server.UrlEncod e instead. HtmlEncode is generating HTML, as it
would be expected to.

-Mike
Nov 18 '05 #3
"Mike Newton" <MN*****@Addus. com> wrote in message
news:ew******** ******@TK2MSFTN GP10.phx.gbl...

Mike & Silva,
Try Server.UrlEncod e instead. HtmlEncode is generating HTML, as it
would be expected to.


Thanks very much. Is the MSDN topic wrong, then...?
Nov 18 '05 #4

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

Similar topics

0
1567
by: Hraklhs | last post by:
Is it useful to ALWAYS use Server.HTMLEncode when writing data read from a db? Ex. Response.Write (Server.HTMLEncode(var)) instead of Response.Write var
4
4089
by: abcd | last post by:
Simple but not working at this moment I have to fill the HTML select control.... my values could be for example "test number 1" sample code, dim x Data = "test number 1"
4
10660
by: Andrea Williams | last post by:
I have a class that imports System.Web.UI.Page. The code below works: public string JScriptEncode(string strValue) { strValue = strValue.Replace(@"'", "\x27"); //' JScript encode apostrophes strValue = strValue.Replace(@"""", "\x22"); //' JScript encode double-quotes
3
4114
by: Michael Gaillez | last post by:
Hi, I'm dynamically loading an assembly into an ASP.NET application. In the control that I load from that dynamic assembly I've tried to use Server.HTMLEncode but this results in a serious performance loss. Is there anyone who knows why or is there an alternative for server.htmlencode method? Without the server.htmlencode the thingy works very fine. greetz
3
1762
by: TCB | last post by:
Hi, There are a couple of things that are bothering me, any help on these is greatly appreciated. This is using ASP.NET 2.0 1. I am sending email in my web app, using a simple form here is the code: Dim MyMailFrom As New Net.Mail.MailAddress("portal@xxx.com", "Portal XX.com") Dim MyMailTo As New Net.Mail.MailAddress("info@xxx.com")
4
4969
by: Fossie | last post by:
Can anyone help with Server.HtmlEncode encoding this? '<%# DataBinder.Eval(Container.DataItem, "CAT_ID", "pageview.aspx?tab=1&catid={0}") %> I've tried using similar to this: <%# Server.HtmlEncode(DataBinder.Eval(Container, "DataItem.Field1").ToString()) %> but get error message BC30455: Argument not specified for parameter '
1
14569
by: Marco Miltenburg | last post by:
While working on some multilingual code I found a rather strange thing happening with Server.HTMLEncode. While loading different languages I change the Codepage and Charset in ASP to reflect the language. This all works fine. However when I tried to use Charset UTF-8 with Codepage 65001 everywhere I found that HTMLEncode always translates all UTF-8 characters to &#xxxx. Example:
1
9525
by: burnsy2000 | last post by:
We are running ASP classic on IIS 5 on W2k SP4. We recently added <% Response.charset="utf-8"%to the top of all our pages (as suggested by validator.w3.org). A problem arose on a page which applies Server.HTMLEncode to a field that was inputted from the user. The problem is that when the user enters a phrase such as: My Fiancé The Server.URLEncode returns the value:
6
2336
by: teddysnips | last post by:
In my application I need to allow users to cut 'n' paste stuff from various sources, some of which might include dodgy characters such as "<". Natch, IE interprets these as potentially dangerous and provides a mechanism to encode/decode them. However I can't seem to get it to work: .... <asp:textbox id=txtDescription style="Z-INDEX: 102; LEFT: 111px; POSITION: absolute; TOP: 124px" tabIndex=29 runat="server" onblur="return...
0
10354
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9177
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7643
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6870
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4314
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3837
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3005
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.