NibblyPig
NibblyPig

Reputation: 52952

Get a controls full ClientID from just ID in asp.net (client side)

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)?

Upvotes: 1

Views: 476

Answers (1)

cjk
cjk

Reputation: 46485

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.

Upvotes: 1

Related Questions