Quotes Around Attribute Values - Optional?

Discussion in 'ASP .Net' started by Jeremy S, Jun 14, 2009.

  1. Jeremy S

    Jeremy S Guest

    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.
     
    Jeremy S, Jun 14, 2009
    #1
    1. Advertising

  2. 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.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Jeremy S" <> wrote in message
    news:u4xYC$...
    > 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.
    >
    >
     
    Nathan Sokalski, Jun 14, 2009
    #2
    1. Advertising

  3. Jeremy S

    Jeremy S Guest

    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!



    "Mark Rae [MVP]" <> wrote in message
    news:%...
    > "Jeremy S" <> wrote in message
    > news:u4xYC$...
    >
    >> Given that both work (i.e., no compiler or runtime errors), do the quotes
    >> matter for any other purpose?

    >
    > Depends which DOCTYPE you're using. If you're using HTML 4.01, quotes
    > round attributes are optional. If you're using XHTML, they're mandatory.
    >
    >> Is there any good reason to include or exclude the quotes?

    >
    > Yes, for cross-browser compatibility. Use the XHTML 1.0 Transitional
    > DOCTYPE, and set the validation schema in Visual Studio also to be XHTML
    > 1.0 Transitional.
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
     
    Jeremy S, Jun 14, 2009
    #3
  4. 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" <> wrote in message news:...
    > 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!
    >
    >
    >
    > "Mark Rae [MVP]" <> wrote in message news:%...
    >> "Jeremy S" <> wrote in message news:u4xYC$...
    >>
    >>> Given that both work (i.e., no compiler or runtime errors), do the quotes matter for any other purpose?

    >>
    >> Depends which DOCTYPE you're using. If you're using HTML 4.01, quotes round attributes are optional. If you're using
    >> XHTML, they're mandatory.
    >>
    >>> Is there any good reason to include or exclude the quotes?

    >>
    >> Yes, for cross-browser compatibility. Use the XHTML 1.0 Transitional DOCTYPE, and set the validation schema in Visual
    >> Studio also to be XHTML 1.0 Transitional.
    >>
    >>
    >> --
    >> Mark Rae
    >> ASP.NET MVP
    >> http://www.markrae.net

    >
    >
     
    Juan T. Llibre, Jun 14, 2009
    #4
  5. "Jeremy S" <> wrote in
    news:u4xYC$:

    > 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! |
    *******************************************
     
    Gregory A. Beamer, Jun 15, 2009
    #5
  6. Jeremy S

    Jeremy S Guest

    >
    > 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, Jun 15, 2009
    #6
  7. "Jeremy S" <> wrote in news::

    >>
    >> 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!


    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! |
    *******************************************
     
    Gregory A. Beamer, Jun 15, 2009
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris White

    Quotes/Double Quotes in Image Control

    Chris White, Sep 22, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    4,853
    Hermit Dave
    Sep 22, 2004
  2. Chris
    Replies:
    1
    Views:
    13,647
    Oisin
    Mar 24, 2006
  3. Lawrence Tierney

    Multiline quotes - escaping quotes - et al

    Lawrence Tierney, Dec 24, 2003, in forum: Java
    Replies:
    3
    Views:
    4,498
    Andrew Thompson
    Dec 24, 2003
  4. jOhn
    Replies:
    1
    Views:
    227
    Phlip
    Jan 29, 2008
  5. Richard Sandoval
    Replies:
    5
    Views:
    205
    7stud --
    Apr 26, 2011
Loading...

Share This Page