AAaron123 said:
However, I have inherited code, from someone who knows much more than I
do, that contains, for example:
onclick="window.location.href='<%=Server.UrlEncode("Locations_list.aspx")
%>'"
onclick='window.location.href="Locations_edit.aspx?Action=New"'
So I thought that maybe if databinding were not involved the rules were
different.
Ok, let me clear up the various usages of quotes. I've read your other post,
and while the reference you linked to is correct, there are other things
going on here.
1. In HTML 4.0 and before, both single and double quotes were valid on
attributes
2. In XHTML, only double quotes are allowed. This is simply because that is
required by the syntax of XML.
3. In ASP.NET server controls, double and single quotes mean very specific
things, as per the databinding rules. (This means that .aspx files are not
strictly valid XML)
4. In Javascript, single and double quotes can be used to denote string. In
your example:
onclick="window.location.href='<%=Server.UrlEncode("Locations_list.aspx")
%>'"
This is a Javascript command:
window.location.href='Locations_list.aspx'
And so the double/single quotes here are down to mixing Javascript in with
attributes. It's better to use double-quotes for all your HTML attributes
(this makes it easy to be XHTML compliant anyway) and then you can use
single-quotes if you need inline Javascript for your element events. I
personally don't like putting Javascript code there anymore, it's much
better to use an external Javascript file and attach events using a
3rd-party library such as jQuery.
I think I have this solved. The string you and Alexey gave me helped much.
The problem I had with CSS is that a HyperLink becomes an anchor and my
CSS anchor attributes were being applied.
I probably could have worked on the CSS code but decided to try to change
to a button.
Hyperlinks ARE anchors. That's how you make hyperlinks in HTML. If you want
certain hyperlnks to look different to others, you give them a CSS class,
and define a CSS style rule to make them appear like buttons. If you don't
do this, you're letting yourself in for an accessibility and standards
nightmare.
HTH
Pete