id vs. name attribute for Html controls

Discussion in 'ASP .Net' started by =?Utf-8?B?Sm9l?=, Dec 8, 2005.

  1. Hello All:

    Does anyone know the difference between the name and id attributes in an
    Html control? I noticed on PostBack that I can not retrieve the
    Request.Form("id_value") but I can retrieve the Request.From("name_value").

    TIA,
    --
    Joe

    VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
    =?Utf-8?B?Sm9l?=, Dec 8, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?Sm9l?=

    Karl Seguin Guest

    It isn't an ASP.Net issue, it's simply how HTML works. When you POST a
    form, the HTML specification mandate that the data be posted in the shape of
    NAME=VALUE&NAME1=VALUE1&NAME2=VALUE2

    It's just how html works.

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "Joe" <> wrote in message
    news:...
    > Hello All:
    >
    > Does anyone know the difference between the name and id attributes in an
    > Html control? I noticed on PostBack that I can not retrieve the
    > Request.Form("id_value") but I can retrieve the
    > Request.From("name_value").
    >
    > TIA,
    > --
    > Joe
    >
    > VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
    Karl Seguin, Dec 8, 2005
    #2
    1. Advertising

  3. =?Utf-8?B?Sm9l?=

    Patrice Guest

    You just get it IMO. My understanding is that "id" is the client side name
    for scripting elements (whatever element you are using) while the "name" is
    the name used server side for submitted values (for example in 2.0 you have
    no more the "name" attribute for a form as the form itself doesn't have a
    name server side).


    --
    Patrice

    "Joe" <> a écrit dans le message de
    news:...
    > Hello All:
    >
    > Does anyone know the difference between the name and id attributes in an
    > Html control? I noticed on PostBack that I can not retrieve the
    > Request.Form("id_value") but I can retrieve the

    Request.From("name_value").
    >
    > TIA,
    > --
    > Joe
    >
    > VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
    Patrice, Dec 8, 2005
    #3
  4. Thanks Karl,

    So, what is the id attribute for?

    TIA,
    --
    Joe

    VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


    "Karl Seguin" wrote:

    > It isn't an ASP.Net issue, it's simply how HTML works. When you POST a
    > form, the HTML specification mandate that the data be posted in the shape of
    > NAME=VALUE&NAME1=VALUE1&NAME2=VALUE2
    >
    > It's just how html works.
    >
    > Karl
    >
    > --
    > MY ASP.Net tutorials
    > http://www.openmymind.net/
    >
    >
    > "Joe" <> wrote in message
    > news:...
    > > Hello All:
    > >
    > > Does anyone know the difference between the name and id attributes in an
    > > Html control? I noticed on PostBack that I can not retrieve the
    > > Request.Form("id_value") but I can retrieve the
    > > Request.From("name_value").
    > >
    > > TIA,
    > > --
    > > Joe
    > >
    > > VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation

    >
    >
    >
    =?Utf-8?B?Sm9l?=, Dec 8, 2005
    #4
  5. =?Utf-8?B?Sm9l?=

    Karl Seguin Guest

    Id is used in the document object model (DOM) of the page. In other words,
    it's chiefly used with javascript. Name attributes musn't be unique, which
    you often see when using radio's or checkboxes (groups all share the same
    name). Id's should be.

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "Joe" <> wrote in message
    news:...
    > Thanks Karl,
    >
    > So, what is the id attribute for?
    >
    > TIA,
    > --
    > Joe
    >
    > VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
    >
    >
    > "Karl Seguin" wrote:
    >
    >> It isn't an ASP.Net issue, it's simply how HTML works. When you POST a
    >> form, the HTML specification mandate that the data be posted in the shape
    >> of
    >> NAME=VALUE&NAME1=VALUE1&NAME2=VALUE2
    >>
    >> It's just how html works.
    >>
    >> Karl
    >>
    >> --
    >> MY ASP.Net tutorials
    >> http://www.openmymind.net/
    >>
    >>
    >> "Joe" <> wrote in message
    >> news:...
    >> > Hello All:
    >> >
    >> > Does anyone know the difference between the name and id attributes in
    >> > an
    >> > Html control? I noticed on PostBack that I can not retrieve the
    >> > Request.Form("id_value") but I can retrieve the
    >> > Request.From("name_value").
    >> >
    >> > TIA,
    >> > --
    >> > Joe
    >> >
    >> > VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation

    >>
    >>
    >>
    Karl Seguin, Dec 8, 2005
    #5
  6. Thanks Karl. This helps.
    --
    Joe

    VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


    "Karl Seguin" wrote:

    > Id is used in the document object model (DOM) of the page. In other words,
    > it's chiefly used with javascript. Name attributes musn't be unique, which
    > you often see when using radio's or checkboxes (groups all share the same
    > name). Id's should be.
    >
    > Karl
    >
    > --
    > MY ASP.Net tutorials
    > http://www.openmymind.net/
    >
    >
    > "Joe" <> wrote in message
    > news:...
    > > Thanks Karl,
    > >
    > > So, what is the id attribute for?
    > >
    > > TIA,
    > > --
    > > Joe
    > >
    > > VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
    > >
    > >
    > > "Karl Seguin" wrote:
    > >
    > >> It isn't an ASP.Net issue, it's simply how HTML works. When you POST a
    > >> form, the HTML specification mandate that the data be posted in the shape
    > >> of
    > >> NAME=VALUE&NAME1=VALUE1&NAME2=VALUE2
    > >>
    > >> It's just how html works.
    > >>
    > >> Karl
    > >>
    > >> --
    > >> MY ASP.Net tutorials
    > >> http://www.openmymind.net/
    > >>
    > >>
    > >> "Joe" <> wrote in message
    > >> news:...
    > >> > Hello All:
    > >> >
    > >> > Does anyone know the difference between the name and id attributes in
    > >> > an
    > >> > Html control? I noticed on PostBack that I can not retrieve the
    > >> > Request.Form("id_value") but I can retrieve the
    > >> > Request.From("name_value").
    > >> >
    > >> > TIA,
    > >> > --
    > >> > Joe
    > >> >
    > >> > VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
    > >>
    > >>
    > >>

    >
    >
    >
    =?Utf-8?B?Sm9l?=, Dec 8, 2005
    #6
  7. =?Utf-8?B?Sm9l?=

    Bruce Barker Guest

    this is partially correct.

    the name attribute is only valid on the <form> and form elements
    (<input>,<textarea> and <select>). it used to specify the name to assoicate
    with the name/value pair that is submitted on a form post.

    for example:

    <input type=checkbox name=foo value=1>

    if checked will submit foo=1. in the dom you can reference form elements
    from the form.elements collection by specifing the name as the index. if is
    not unique, the collection returns an array of elements rather than the
    element. modern dom's support looking up form elements by name as:

    document.getElementsByName(nameValue)

    note: it always returns an array even if only one element is found.


    id attribute is from the xml world, and is a unique id for any node, not
    just form elements. unlike the name attribute it is valid on any html node.
    also like the name attribute, it must follow the valid identitfier rules.
    the identitfer should start with an alpha, and only contain alpha
    ([a-zA-Z]), numbers, hyphen, underscore and colons.(note aspnet breaks this
    rule by starting reserved ids with a underscore - thus they will alway fail
    an html/xml lint - actually some proxies strip them). to find any html
    element by id you use:

    document.getElementById(idvalue)

    this only returns one dom node.

    -- bruce (sqlwork.com)









    "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    wrote in message news:%23u1JvXA$...
    > Id is used in the document object model (DOM) of the page. In other
    > words, it's chiefly used with javascript. Name attributes musn't be
    > unique, which you often see when using radio's or checkboxes (groups all
    > share the same name). Id's should be.
    >
    > Karl
    >
    > --
    > MY ASP.Net tutorials
    > http://www.openmymind.net/
    >
    >
    > "Joe" <> wrote in message
    > news:...
    >> Thanks Karl,
    >>
    >> So, what is the id attribute for?
    >>
    >> TIA,
    >> --
    >> Joe
    >>
    >> VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
    >>
    >>
    >> "Karl Seguin" wrote:
    >>
    >>> It isn't an ASP.Net issue, it's simply how HTML works. When you POST a
    >>> form, the HTML specification mandate that the data be posted in the
    >>> shape of
    >>> NAME=VALUE&NAME1=VALUE1&NAME2=VALUE2
    >>>
    >>> It's just how html works.
    >>>
    >>> Karl
    >>>
    >>> --
    >>> MY ASP.Net tutorials
    >>> http://www.openmymind.net/
    >>>
    >>>
    >>> "Joe" <> wrote in message
    >>> news:...
    >>> > Hello All:
    >>> >
    >>> > Does anyone know the difference between the name and id attributes in
    >>> > an
    >>> > Html control? I noticed on PostBack that I can not retrieve the
    >>> > Request.Form("id_value") but I can retrieve the
    >>> > Request.From("name_value").
    >>> >
    >>> > TIA,
    >>> > --
    >>> > Joe
    >>> >
    >>> > VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
    >>>
    >>>
    >>>

    >
    >
    Bruce Barker, Dec 8, 2005
    #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. =?Utf-8?B?QW5kZXJzIEphbnNzb24=?=

    Invalid 'name' attribute name

    =?Utf-8?B?QW5kZXJzIEphbnNzb24=?=, Jan 20, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    1,903
    =?Utf-8?B?QW5kZXJzIEphbnNzb24=?=
    Feb 14, 2006
  2. Moonbeam66
    Replies:
    2
    Views:
    427
    Moonbeam66
    Jun 7, 2005
  3. ding feng
    Replies:
    2
    Views:
    2,804
    ding feng
    Jun 25, 2003
  4. bprimuslevy
    Replies:
    1
    Views:
    437
    Soren Kuula
    Aug 23, 2006
  5. Pavils Jurjans
    Replies:
    3
    Views:
    181
    Pavils Jurjans
    Mar 18, 2005
Loading...

Share This Page