Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Re: Dynamically create controls with non-hierarchical IDs

Reply
Thread Tools

Re: Dynamically create controls with non-hierarchical IDs

 
 
John Saunders
Guest
Posts: n/a
 
      07-15-2004
"Simon Wallis" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I have a PlaceHolder inside a repeater so that I can dynamically add

controls to my page. Each time the repeater.ItemDataBound event fires I
create a Label and add it to the PlaceHolder.
>
> Now, when I create this Label, I set the ID to have the dynamic value:
> "lblSubTotal_" + strCurrencyCode;
>
> ASP.NET will turn this Label into a [span] tag in the resulting HTML

output, and I want to manipulate this tag using Javascript. In JS I want to
get a reference to the tag via its ID value. For example:
> objCurrencySubtotal = document.getElementById("lblSubTotal_USD");
>
> The problem is that when ASP.NET creates the [span] tag, it modifies the

ID value by prepending a whole bunch of hierarchically-qualified info. For
example, this is the span tag I end up with in the HTML output:
> <span

id="pbdTemplate__PageTemplate_innerHolder_ctrlBala nces_rptrAggregateTotals__
ctl1_lblSubTotal_USD">
>
> I cannot find this easily using Javascript. Does anyone know how to stop

ASP.NET from prepending all that hierchical info and force it to use the ID
value I myself assign to the control?

Simon,

Another solution is to pass the ID to the JavaScript code. For instance, if
you need to call your JavaScript on a Click event:

lblClickMe.Attributes.Add("onclick",
string.Format("MyJSFunction('{0}');", myLabel.UniqueID));

MyJSFunction will then be able to get the element using getElementById.
--
John Saunders
johnwsaundersiii at hotmail


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
after transfer of data from MS-outlook(mail ids) to application,mail ids are consisting of strange characters vamsikrishna_b@coolgoose.com Python 2 06-21-2005 12:41 PM
FindControl requires that controls have unique IDs SouthSpawn ASP .Net 1 04-22-2005 01:38 AM
User Control and Controls IDs problem =?Utf-8?B?UmFlZCBTYXdhbGhh?= ASP .Net 3 02-12-2005 04:18 PM
generate control IDs dynamically =?Utf-8?B?Tmljaw==?= ASP .Net 1 06-13-2004 01:06 PM
Multiple controls with the same ID '_ctl24' were found. Trace requires that controls have unique IDs Jeff Tolman ASP .Net 0 11-04-2003 09:53 PM



Advertisments