Quotes Around Attribute Values - Optional?

J

Jeremy S

Both of the following work (i.e., they declare a Web Server control).

<asp:DropDownList ID=DropDownList1 runat=server></asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server"></asp:DropDownList>

The only difference is that the attribute values are wrapped in quotes, or
they are not wrapped in quoted.

Given that both work (i.e., no compiler or runtime errors), do the quotes
matter for any other purpose? Is there any good reason to include or exclude
the quotes?

Thanks.
 
N

Nathan Sokalski

I'm not sure why it is working without the quotes, but whether it works or
not without them you should include them. The reason for this is because
standards specify that all attribute values must be enclosed in quotation
marks. You should notice that if you remove the quotation marks Visual
Studio will give you a validation error. Hopefully this helps.
 
J

Jeremy S

What about attributes useful to only to server-side logic?

Clearly, and for example runat="server" never gets rendered to the
browser... consequently DocType and browser standards are not relevant.

Any good "server-side reasons" to include the quotes?

Just curious... I'm not solving any real problem here.

Thanks!
 
J

Juan T. Llibre

re:
!> What about attributes useful to only to server-side logic?

VS complains if you don't include the quotes.
Otherwise, you can feel free to use quotes or not use them.




===============
Jeremy S said:
What about attributes useful to only to server-side logic?

Clearly, and for example runat="server" never gets rendered to the browser... consequently DocType and browser
standards are not relevant.

Any good "server-side reasons" to include the quotes?

Just curious... I'm not solving any real problem here.

Thanks!
 
G

Gregory A. Beamer

Both of the following work (i.e., they declare a Web Server control).

<asp:DropDownList ID=DropDownList1 runat=server></asp:DropDownList>
<asp:DropDownList ID="DropDownList2"
runat="server"></asp:DropDownList>

The only difference is that the attribute values are wrapped in
quotes, or they are not wrapped in quoted.

Given that both work (i.e., no compiler or runtime errors), do the
quotes matter for any other purpose? Is there any good reason to
include or exclude the quotes?


Quotes are proper form and required for some DOCTYPES. And while things
might not "blow up" if you do not use the quotes, you may find your code
not working in the future when MS decides to become more XML compliant
with their output code.

The VS editor, as you move forward in time, gets better at XHTML
compliance and will do more to put in quotes for you. Some third party
tools also put in the quotes, even when VS does not.

The only reason I can see for not putting in quotes, server side or
otherwise, is you are saving two keystrokes per thing you code, but
since there is a potential downside risk, and the time savings for two
strokes is so small, I think it is rather insane not to type them in.
 
J

Jeremy S

The only reason I can see for not putting in quotes, server side or
otherwise, is you are saving two keystrokes per thing you code, but
since there is a potential downside risk, and the time savings for two
strokes is so small, I think it is rather insane not to type them in.


Agreed. - just satisfying a curiosity here, not trying to justify any
lazinesss. Thanks!
 
G

Gregory A. Beamer

Jeremy S said:
Agreed. - just satisfying a curiosity here, not trying to justify any
lazinesss. Thanks!

No problem. The group is also perused by others that might think not
mentioning it is a bad idea means it is a good idea. ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top