Execute JavaScript from Page_Load

  • Thread starter Thread starter Scott Natwick
  • Start date Start date
S

Scott Natwick

Is there a way to execute a JavaScript from the Page_Load event?

Or alternatively, is there a way to have it execute when the page is loaded?

I am defining the script in the Page_Load event and using the
RegisterStartupFunction to add it to the page. I just need a way to execute
the script when the page loads.

Any ideas?

Thanks in advance,
Scott
 
Look into using the body onload event. This JavaScript event will be fired
once the complete file is sent to the user.

HTH MikeL
 
Thanks, Mike.

I appreciate the response.

I tried triggering the function from the "onload" event of the "body," like
you suggested.

However, the message I get is " undefined:NaN". I think maybe the timing is
off or somthing?

If I add a button to the page and have the button call the function, it
works.

Any thoughts on this?

Thanks again,
Scott
 
Thanks for the response, Mike.

I tried what you suggest. I added the function call to the "onload" event
of the "body."

However, I received the message " undefined:NaN" as a result of the function
call.

I think maybe the timing may be off?

If I trigger the function call from a button, once the page is loaded, it
works.

Any thoughts?

Thanks again,
Scott
 
Scott,

It sounds like the JavaScript function is not being loaded onto the page
before the body tag. To see if this is happening save the page as HTML and
open it up in IE. It it works then, then it is a load problem. Try
registering the script in the page load event.

HTH MikeL
 
Back
Top