Execute JavaScript from Page_Load

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
 
G

Guest

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

HTH MikeL
 
S

Scott Natwick

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
 
S

Scott Natwick

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
 
G

Guest

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
 

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

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top