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 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
"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
After writing my own HtmlEncode method, I realised that ' 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
Try using ' instead of '.
"Andy Fish" <aj****@blueyonder.co.uk> wrote in message
news:uJ**************@TK2MSFTNGP15.phx.gbl... After writing my own HtmlEncode method, I realised that ' 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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
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,...
| |