473,668 Members | 2,386 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.getEl ementById('" & Me.ctrl.ClientI D & "')"

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********@hotm ail.com
http://www.nathansokalski.com/
Nov 18 '06 #1
2 3482
"Nathan Sokalski" <nj********@hot mail.comwrote in
news:ec******** ******@TK2MSFTN GP03.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
That is irrelevant, and doesn't make sense. First of all, MyLabel is NOT the
same as MyUserControl_M yLabel; if I were to refer to MyLabel only one of
those would match it. Second, using your logic of potentially having two
objects with the same name would apply to the id attribute as well, because
if somebody (for some unknown reason) decided to give a control that was not
runat="server" the same id as the id generated by a runat="server" using

"document.getEl ementById('" & Me.ctrl.ClientI D & "')"

would not know which element to get either, but ASP.NET included a ClientID
property. I see no difference between the potential problems, so why did
they give us ClientID but not ClientName?
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Spam Catcher" <sp**********@r ogers.comwrote in message
news:Xn******** *************** **********@127. 0.0.1...
"Nathan Sokalski" <nj********@hot mail.comwrote in
news:ec******** ******@TK2MSFTN GP03.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 19 '06 #3

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

Similar topics

0
1367
by: Nathan Ernst | last post by:
I have a pretty simple XSD schema: ******************************************** * XSD SCHEMA ******************************************** <?xml version="1.0" encoding="utf-8" ?> <xs:schema id="PageHitStatistics" targetNamespace="urn:PageHitStatistics" elementFormDefault="qualified" xmlns="urn:PageHitStatistics"
1
1791
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 attributes I put inside xsl:element tagcannot be generated. Part of the XML data: <?xml version="1.0" encoding="utf-8"?> <receipients> <receipient> ... <ServerUrl>http://win2003p2/</ServerUrl>...
0
3024
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 to an XML schema (xsd).
5
7282
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 properties.xsd this creates properties.cs
5
2159
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 intellisense when I specify the name space. But leaving hte namespace in messes up my transforms. Is there any way to get this intellisense functionality without adding the namespace all the time? Thanks,
1
1071
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 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...
4
2375
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. Because I want to use some ajax-requests and other javascript-functions on my xhtml, I need to dynamically add event handlers to any possible dom-elements. All solutions I found so fare are for specific, pre-known
8
7038
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" xmlns:dino="http://example.com/test" targetNamespace="http://example.com/test" elementFormDefault="qualified">
1
2613
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 User</name> <email>myuser@domain.com</email> <manager>manager@domain.com</manager>
1
2319
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 = "tnName".../>
0
8459
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8378
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8890
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8791
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7398
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6206
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5677
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2018
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1783
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.