473,405 Members | 2,445 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,405 software developers and data experts.

HtmlEncode with apostrophes

When using databinding, I have gotten into the habit of using single quotes
(apostrophe) round attribute values rather than double quotes because this
allows visual studio to work when there are quotation marks in the
databinding expression. As far as I can tell this seems to be recommended
practice.

However, I just realised that HtmlEncode doesn't encode apostrophes, so if
you do something like this

<a href=... title='<%#Server.HtmlEncode(DataBinder.Eval(Contai ner,
"DataItem.FullName"))%>' >

you will be screwed if the full name contains an apostrophe.

Is it really unacceptable to use single quotes for HTML attribute values?
Assuming not, does this mean I have to write my own version of HtmlEncode?

TIA

Andy
Nov 19 '05 #1
4 4615
"Andy Fish" <aj****@blueyonder.co.uk> wrote in message
news:OB*************@TK2MSFTNGP15.phx.gbl...
When using databinding, I have gotten into the habit of using single
quotes (apostrophe) round attribute values rather than double quotes
because this allows visual studio to work when there are quotation marks
in the databinding expression. As far as I can tell this seems to be
recommended practice.
"Recommended" might be pushing things a bit. <g> It works, but consistently
using double quotes to wrap attributes will generally make your HTML a bit
easier to maintain.

However, I just realised that HtmlEncode doesn't encode apostrophes,
But it will encode the double quote character, so things would be a bit
easier if you were wrapping with double quotes.

so if you do something like this

<a href=... title='<%#Server.HtmlEncode(DataBinder.Eval(Contai ner,
"DataItem.FullName"))%>' >

you will be screwed if the full name contains an apostrophe.

Is it really unacceptable to use single quotes for HTML attribute values?
You can do it, but it will require a bit more work.

Assuming not, does this mean I have to write my own version of HtmlEncode?
You should really do this anyway in order to facilitate handling of other
"interesting" scenarios (e.g.: encoding of text to be used as a literal
string in client-side javascript). The easiest way to implement this is to
call the provided HtmlEncode method, then massage the resulting string as
required for its intended used.


TIA

Andy

Nov 19 '05 #2
"Andy Fish" <aj****@blueyonder.co.uk> wrote in message
news:OB*************@TK2MSFTNGP15.phx.gbl...
When using databinding, I have gotten into the habit of using single
quotes (apostrophe) round attribute values rather than double quotes
because this allows visual studio to work when there are quotation marks
in the databinding expression. As far as I can tell this seems to be
recommended practice.
"Recommended" might be pushing things a bit. <g> It works, but consistently
using double quotes to wrap attributes will generally make your HTML a bit
easier to maintain.

However, I just realised that HtmlEncode doesn't encode apostrophes,
But it will encode the double quote character, so things would be a bit
easier if you were wrapping with double quotes.

so if you do something like this

<a href=... title='<%#Server.HtmlEncode(DataBinder.Eval(Contai ner,
"DataItem.FullName"))%>' >

you will be screwed if the full name contains an apostrophe.

Is it really unacceptable to use single quotes for HTML attribute values?
You can do it, but it will require a bit more work.

Assuming not, does this mean I have to write my own version of HtmlEncode?
You should really do this anyway in order to facilitate handling of other
"interesting" scenarios (e.g.: encoding of text to be used as a literal
string in client-side javascript). The easiest way to implement this is to
call the provided HtmlEncode method, then massage the resulting string as
required for its intended used.


TIA

Andy


Nov 19 '05 #3
After writing my own HtmlEncode method, I realised that &apos; is not part
of the HTML 4 standard and also IE does not support it.

I conclude that it is not possible to use single quotes round attribute
values if the attribute value could itelf contain a single quote mark (i.e.
apostrophe). It seems unfortunate that so many examples use this style.

"Nicole Calinoiu" <calinoiu REMOVETHIS AT gmail DOT com> wrote in message
news:e6****************@TK2MSFTNGP09.phx.gbl...
"Andy Fish" <aj****@blueyonder.co.uk> wrote in message
news:OB*************@TK2MSFTNGP15.phx.gbl...
When using databinding, I have gotten into the habit of using single
quotes (apostrophe) round attribute values rather than double quotes
because this allows visual studio to work when there are quotation marks
in the databinding expression. As far as I can tell this seems to be
recommended practice.


"Recommended" might be pushing things a bit. <g> It works, but
consistently using double quotes to wrap attributes will generally make
your HTML a bit easier to maintain.

However, I just realised that HtmlEncode doesn't encode apostrophes,


But it will encode the double quote character, so things would be a bit
easier if you were wrapping with double quotes.

so if you do something like this

<a href=... title='<%#Server.HtmlEncode(DataBinder.Eval(Contai ner,
"DataItem.FullName"))%>' >

you will be screwed if the full name contains an apostrophe.

Is it really unacceptable to use single quotes for HTML attribute values?


You can do it, but it will require a bit more work.

Assuming not, does this mean I have to write my own version of
HtmlEncode?


You should really do this anyway in order to facilitate handling of other
"interesting" scenarios (e.g.: encoding of text to be used as a literal
string in client-side javascript). The easiest way to implement this is
to call the provided HtmlEncode method, then massage the resulting string
as required for its intended used.


TIA

Andy


Nov 19 '05 #4
Try using ' instead of &apos;.

"Andy Fish" <aj****@blueyonder.co.uk> wrote in message
news:uJ**************@TK2MSFTNGP15.phx.gbl...
After writing my own HtmlEncode method, I realised that &apos; is not part
of the HTML 4 standard and also IE does not support it.

I conclude that it is not possible to use single quotes round attribute
values if the attribute value could itelf contain a single quote mark
(i.e. apostrophe). It seems unfortunate that so many examples use this
style.

"Nicole Calinoiu" <calinoiu REMOVETHIS AT gmail DOT com> wrote in message
news:e6****************@TK2MSFTNGP09.phx.gbl...
"Andy Fish" <aj****@blueyonder.co.uk> wrote in message
news:OB*************@TK2MSFTNGP15.phx.gbl...
When using databinding, I have gotten into the habit of using single
quotes (apostrophe) round attribute values rather than double quotes
because this allows visual studio to work when there are quotation marks
in the databinding expression. As far as I can tell this seems to be
recommended practice.


"Recommended" might be pushing things a bit. <g> It works, but
consistently using double quotes to wrap attributes will generally make
your HTML a bit easier to maintain.

However, I just realised that HtmlEncode doesn't encode apostrophes,


But it will encode the double quote character, so things would be a bit
easier if you were wrapping with double quotes.

so if you do something like this

<a href=... title='<%#Server.HtmlEncode(DataBinder.Eval(Contai ner,
"DataItem.FullName"))%>' >

you will be screwed if the full name contains an apostrophe.

Is it really unacceptable to use single quotes for HTML attribute
values?


You can do it, but it will require a bit more work.

Assuming not, does this mean I have to write my own version of
HtmlEncode?


You should really do this anyway in order to facilitate handling of other
"interesting" scenarios (e.g.: encoding of text to be used as a literal
string in client-side javascript). The easiest way to implement this is
to call the provided HtmlEncode method, then massage the resulting string
as required for its intended used.


TIA

Andy



Nov 19 '05 #5

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

Similar topics

3
by: James Foreman | last post by:
I've got a set of emails in a table, where sometimes they've failed to input the @ properly. Eg james.foreman'abcmail.co.uk How do I write a replace to deal with that? Also, I've got a set...
3
by: Richard Hollenbeck | last post by:
I have an email field and a command button to send email. The problem is that when the email program opens up there are apostrophes around the email address that I have to manually remove before...
4
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...
3
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...
3
by: David Lozzi | last post by:
Howdy, I have my left navigation of Hyperlinks, and part of the link's querystring is the title of the page they are going to. For example, one of the pages is Cars & Trucks. With HtmlEncode, it...
1
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...
1
by: Alexander Higgins | last post by:
>>Thanks for the response.... Point Taken but this is not the case. Thus, if a person writes a text file on her or his computer and does not use UNICODE to save it, the current code page is...
4
by: Lucanos | last post by:
Hey Guys, Probably a simple question, but one I am struggling with all the same. I know that in PHP you wrap a text string in apostrophes or quotations - (examples $variable = 'this string' OR...
2
by: =?Utf-8?B?bXVzb3NkZXY=?= | last post by:
Hi I'm trying to code up an admin system for my website. A couple of the welcome text paragraphs are stored in an SQL database, so that we can update them should we need to. However, even though...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...

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.