elements not loaded before RegisterStartupScript

C

Crazy Cat

In the page load event of my user control I create and register a
startup script with RegisterStartupScript. I am passing two controls
(using the ClientID property of the controls) into a function in the
startup script and I get
an undefined error on one of them (an image control) while the other
(a div) is found with no problem. Additionally even
if I comment out all references to the undefined control (except the
in the argument list for the function) I get the undefined error and
the function does not run. What the hell -- why should it stop with an
undefined argument if the argument is not used?

Please HELP!!!!
 
G

Guest

You may wish to use Firebug and Firefox together to debug this , however in
regards to the objects not loading before the script executes - you either
need to push the script to be rendered at the end of the page, subscribe to
the body's onload event and do your stuff there or have a setTimeout that
tries to get the element , if it's null then wait naother 500-1000
milliseconds and check again.
Ideally - you're probably gonna be better off subscribing to the body's
onload event.
 
M

Muhammad Naveed Yaseen

Images usually have natural latency of being loaded later than
document. Put startup script instead in onload event of image like
<img onload="javascript:startup(x,y);" .... /> (or if server-side
Image control then ImageXyz.Attributes["onload"] =
"javascript:startup(x,y);";
 
C

Crazy Cat

Images usually have natural latency of beingloadedlater than
document. Put startup script instead in onload event of image like
<img onload="javascript:startup(x,y);" .... /> (or if server-side
Image control then ImageXyz.Attributes["onload"] =
"javascript:startup(x,y);";

This code is going to be in a user control. If I subscribe to the
form's body onload event what if the parent page has its body onload
event already specified? Wouldn't that
render either my control's body.onload event useless or the parent
page's onload event useless?

I tried to do this in the onload event for the image but the script is
still loading before the image (this is being handled server-side
since the clientside image control does not handle an onload event).

Much as I hate it it looks like I'll have to implement Yaseen's
solution and wait and check for the image to be loaded.

Thanks,

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top