Quotes Around Attribute Values - Optional?

  • Thread starter Thread starter Jeremy S
  • Start date Start date
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.
 
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.
 
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!
 
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.




Juan T. Llibre, asp.net MVP
¿ Estas probando VS 2010 y ASP.NET 4.0 ?
Regístrate (gratis) en los Foros de VS 2010 y ASP.NET 4.0, en español
http://asp.net.do/foros/forums/
=====================================================
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!
 
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.


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
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!
 
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. ;-)

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Back
Top