Cannot get Callback object using getElementById

This post has 4 replies

Top 100 Contributor
Posts: 49
comet Posted: Mon Mar 3, 2008 @ 9:36 AM
Hi,

Is there any reason why I cannot get the Callback object using getElementById?

I tried the following:
alert("print Object directly:" + callback1);
alert("print Object using getElementById:" + document.getElementById("callback1"));

The first line returns an object and the second line return null.

Do I need to do something special to get the Callback object?

Thanks.
Top 500 Contributor
Posts: 20
preseaug Posted: Tue Mar 25, 2008 @ 6:24 AM
I have the same question.

Can somebody answer us please?

Thanks.
Top 10 Contributor
Posts: 6,424
hwan Posted: Mon Apr 7, 2008 @ 1:36 PM
The JavaScript method document.getElementById() returns the HTML DOM element. However, Web.UI controls create themselves dynamically as Objects on the client, complete with properties, methods and events (as described in the client API docs). This is in addition to their HTML DOM element (usually a TABLE).

Thus, when you want to access the Web.UI object, you directly access it via its object name.
eg.
<code>
CallBack1.callback();
</code>
or more succinctly,
<code>
window.CallBack1.callback();
</code>

If instead you want to access the DOM element, you can use the getElementById() document method as you've done above.

Note that in both cases you may have to account for the ID changing if the control is in a UserControl or Master/Content page etc.

I hope this clears things up!
Not Ranked
Posts: 8
pprabhakaran Posted: Mon Jan 30, 2012 @ 2:09 PM
I have a Chart control in a Usercontrol. Could someone tell me how I could get to the ID so that i could set the width of the chart in a javascript on the client side.

What would like to do is replace this with something that would work
 
var chartElement =  document.getElementById(<%=Chart.ClientID%>.get_id());
chartElement  .style.width = "300" +"px" ;

 
Top 10 Contributor
Posts: 694
ajay Posted: Tue Jan 31, 2012 @ 4:01 AM

Hello,

 

You need to first enable the client-side API of Chart to work at client side. Please refer the following help article to work with it:

 

http://docs.componentart.com/#UIFramework/2012/ComponentArt.Web.UI.AJAX/Chart_clientside_api.htm

 

However you cannot change its width from client side.

 

Thank you.

 

Ajay Mishra

Page 1 of 1 (5 items)