473,506 Members | 16,994 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

checkboxes dynamicaly

When creating checkboxes dynamically, I assign the ID property as follows :
chkBox.ID ="myID", when runing the ASPX page I see a name attribute in the
input
*************************************
<input id="30R" type="checkbox" name="30R5149"........
**************************************
The object checkbox does not have "name" property. The 1st question, is it
possible to give ita name different fromthe id,if yes how ?
2nd question, I want to give the same name for several checkboxes in order
to, later, using javascript to loop this group of checkboxes. Just 10
mlinutes ago I posted another question related this issue

Thanks
Oct 26 '06 #1
2 1410
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 <formand 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 (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Oct 27 '06 #2
Sorry my previous reply is not completely right.

At server-side we have three properties: ID, ClientID, UniqueID; the
ClientID and UniqueID is based on ID and generated by three parts:
* the container's according property (if the control is in a container)
* the ID
* the separator: ClientIDSeparator or IdSeparator:

#Control.ClientIDSeparator Property (System.Web.UI)
http://msdn2.microsoft.com/en-us/lib....clientidsepar
ator.aspx

#Control.IdSeparator Property (System.Web.UI)
http://msdn2.microsoft.com/en-us/lib....idseparator.a
spx

At client-side, the id attribute will use ClientID; the name attribute will
use UniqueID.

Note the separators are new in .NET 2.0, in .NET 1.1, the logic is the same.

Oct 27 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
11808
by: Paul | last post by:
I am trying to get a form to dynamicaly add hidden elements. Below is the function I've created, basicaly it loops thru an array and attempts to add those values to a newly created hidden input...
4
2839
by: ZhangZQ | last post by:
Is it possible to dynamicaly to local and call a function in Win32 dll(not a ..net assembly dll) in C# at run time, for example, a C# program popup a dialogbox to let use input which Win32 dll to...
3
1706
by: peter | last post by:
How to create a class dynamicaly at run-time? Some documentations in MSDN say that it is feasible using the class "TypeBuilder",but I don't know how to do. Is there anyone who can help me? Sample...
1
323
by: Daniel | last post by:
How do i dynamicaly load and unload a C# dll at runtime
1
380
by: Daniel | last post by:
how to create a gif or png dynamicaly in .aspx and return in response?
3
1677
by: minigitoo | last post by:
Hi I try to get dynamicaly all requests made to DB2 I process like this: 1) I stop then start my instance of database in the db2 control center 2) I use : db2 update monitor switches using...
3
1401
by: payne747 | last post by:
Hi everyone, Can anyone help me with the following code, for some reason I can't understand if I'm being thick of if javascript is so backwards! HTML defines some checkboxes such as: <form...
7
5837
by: harikap | last post by:
hi , here im using vb.net 2005how can i add radiobuttons as column to windows datagridview control plz help me....
0
7218
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7103
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7021
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
409
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.