views:

41

answers:

1

This problem is the bane of my asp.net coding life.

I have a control, in code, and I want to get its full ClientID but I cannot until I add it to the page.

However I cannot add it to the page yet. I want to add some javascript to the onclick.

I can add something like "myMethod(this)" to the onclick, which is great and sidesteps the problem, but if I want a select all button for example, that runs "myMethod(theItem); myMethod(theItem2); myMethod(theItem3)" then I can no longer use 'this'.

I can't do "myMethod(document.getElementByID('" + myObject.ClientID + "'))'" or whatever either, because the ClientID isn't set yet.

So is there a javascript method that I can paste into my page that will find the element from its ID (ClientID and ID are the same before it is added to the page)?

+1  A: 

You can add it to the page then add the javascript. As long as you still have a reference to the control, you can put it wherever, then any updates will happen to it in-place.

ck
The control is created by a method, so you would call the method to get the control, then add it to the page, which is clean and nice. I am seeking an alternative to then having to diddle with it again after you add it to the page.
SLC
No choice, I call a finalise method after it's added for a couple of bits of functionality that require the clientid
SLC