473,511 Members | 16,068 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting the generated name attribute for use in JavaScript

As most of us probably know, ASP.NET controls do not use an exact copy of a
control's ID for the HTML element's name or id attribute. When generating
JavaScript as part of a control or event, we need to have a way to reference
the HTML elements. The only way I have found to reference the HTML elements
in my generated Javascript is the following:

"document.getElementById('" & Me.ctrl.ClientID & "')"

However, this seems like a lot of extra code for each element. Why do the
controls have a ClientID property but not a ClientName property? If there
were a ClientName property, wouldn't it make the code a lot less complicated
and shorten the amount of JavaScript that had to be included with each
control? Or is this just one of those Microsoft things where they are trying
to get people to use the id attribute rather than the name attribute?
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Nov 18 '06 #1
1 1063
"Nathan Sokalski" <nj********@hotmail.comwrote in
news:ec**************@TK2MSFTNGP03.phx.gbl:
Why do the
controls have a ClientID property but not a ClientName property? If
there were a ClientName property, wouldn't it make the code a lot less
complicated and shorten the amount of JavaScript that had to be
included with each control? Or is this just one of those Microsoft
things where they are trying to get people to use the id attribute
rather than the name attribute?
You can potentially have two objects using the same ClientName - i.e.:

Form
+MyLabel
+MyUserControl
+MyLabel

Thus the Form can have a MyLabel and a MyUserControl MyLabel... so if you
were to refer to MyLabel, which label is it? :-)

But in anycase, you *could* refer to objects by name ... if you know the
exact layout of the page. If you take a close look at the element IDs,
they're generated the same each time (provided the control nesting does not
change).
Nov 18 '06 #2

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

Similar topics

0
1339
by: Nathan Ernst | last post by:
I have a pretty simple XSD schema: ******************************************** * XSD SCHEMA ******************************************** <?xml version="1.0" encoding="utf-8" ?> <xs:schema...
1
1783
by: Wayne Lian via .NET 247 | last post by:
Hi all, Just wonder anyone have encountered this problem before?I tried using XMLSPY debugger and I can get the correct outputfor my XSLT transformation, however in .net, aftertransformation the...
0
3008
by: keith bannister via .NET 247 | last post by:
(Type your message here) -------------------------------- From: keith bannister Hi, I'm new to .net (as of last week) but here goes. I want to serialize/deserialize a file the conforms...
5
7269
by: Keith Bannister | last post by:
I'm new to .net so here goes. I'm tying to deserialize a class that is associated with an XML schema. I created the C# class with xsd.exe as below: xsd.exe /c /n:somenamespace...
5
2151
by: Don | last post by:
Hi: I have created an xsd from my xml document. I pop this xsd in the following directory: C:\program files\Microsoft Visual Studio .NET 2003\Common7\Packages\schemas\xml. That give me...
2
3471
by: Nathan Sokalski | last post by:
As most of us probably know, ASP.NET controls do not use an exact copy of a control's ID for the HTML element's name or id attribute. When generating JavaScript as part of a control or event, we...
8
7025
by: Les Caudle | last post by:
Using this command line to run XSD.exe xsd /c /o:outputDir input.xsd /f on the following XSD <?xml version="1.0"?> <schema xmlns="http://www.w3.org/2001/XMLSchema"...
1
2605
by: Chris White | last post by:
Here's my XML <?xml version="1.0" encoding="UTF-8"?> <results> <status code="ok"/> <report-bulk-users> <row principal-id="23859115" type="user"> <login>muser@domain.com</login> <name>My...
1
2311
by: Ben Brown | last post by:
I'm having some problems.. I have some javascript generated input elements with dynamic names and values. ex: <input name = "t1Name" .../> <input name = "t2Name" .../> ..... <input name =...
0
7242
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
7418
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
7075
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
5662
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
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3222
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
3212
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
446
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.