Hi,
To answer your question, we need to understand the relationship between
server-side ID, ClientID and client-side id, name attributes.
At server-side, we can only change the ID property, the ClientID is
readonly, and it will not necessary equal to the ID property. This is
because we can put child controls inside a container which implements
INamingContainer interface which is a marker interface. ASP.NET will
generate the ClientID based on which container the control belongs, so that
you only need to make sure the ID is unique in the same container, and
ASP.NET will generate ClientID that is unique in the whole page.
For client-side, the name attribute is only valid on the <form> and form
elements (<input>, <textarea>, and <select>). It is used to specify the
name to associate with the name/value pair that is submitted on a form post.
For example:
<input type=checkbox name=foo value=1>
If this checkbox is checked, it will submit foo=1. In the dom you can
reference form elements from the form.elements collection by specifying the
name as the index. If it's not unique, the collection returns an array of
elements rather than the element:
document.getElementsByName(nameValue)
Note: it always returns an array even if only one element is found.
Client-side id attribute is from the xml world, and is a unique id for any
node, not just form elements, and unlike the name attribute it is valid on
any html node. To find the element by id:
document.getElementById(idValue)
As for ASP.NET generated html, the id and name (if this is one of the three
tags that can submit data) attributes will always equal to server-side
ClientID, which is guaranteeded to be unique on the page. Also, the name
attribute is required to postback the data to server-side code so that
ASP.NET will know which server-side property is changed.
In a short, actually you can't control which name attribute at client-side
to user, it depends on your server-side ID property and which container the
control is in. If you change the name attribute and server-side code
doesn't have the knowledge of this, the postback data will be lost since
server-side code cann't map the postback data to correct properties.
Sincerely,
Walter Wang (
[email protected], remove 'online.')
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.