473,395 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 802
"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
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
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
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
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
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...
1
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...
4
by: simon | last post by:
hi, I would like to separate my javascript completely from my xhtml. in the end there should be only <script type="text/javascript" src="javalib.js"></script> in the head-tag to my javascript....
8
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.