I have a web form that contains a usercontrol and I would like to be able to access the html elements within the usercontrol from the form page using javascript.
I tried the following:
document.getElementById('<%= usercontrol.clientid %>')
but this returned null.
I had a look around with firebug and found that the tags in the usercontrol render with clientids like usercontrolid_myelement. I’m guessing that something like this might work:
document.getElementById('<%= usercontrol.clientid %>'+'_myelement')
Is there a better/nicer way of doing this?
I have seen through your question with my psychic powers!
Your problem is that your serverscript in your main page can’t access the ASP.net elements of your usercontrol.
The solution is to expose the elements, or just the ClientIDs of the elements you need, through properties in the usercontrol. Then you can use the ClientIDs in Javascript like you want to.