RegisterStartupScript vs <Body onload="x()">

C

cmay

I have recently been working with RegisterStartScript in my asp.net
pages.

However, as you probably know it places the script at the end of the
FORM tag.

However, when this code executes on the client, there is no guarantee
that the document has finished loading, and that the DOM is ready to be
accessed.

In other words, people typically use the body tags onload event to kick
off their init code rather than putting the script at the bottom of the
page because if you have large HTML document and you try to execute the
code document.getElementByID("asdf") and the DOM has not finished
loading (readState <> "completed") then this will thrown an error.

Has anyone else had this problem, or seen any mention of the issue by
Microsoft?

I wrote a workaround that uses setTimeout to keep checking for the
document to finish loading before it runs all my init code, but it is
kind of a pain, and the fact that I don't see any other mentions of
this issue make me wonder if there is something else that can be done,
or if I am doing something wrong.
 
K

Kevin Spencer

If you put all of your client-side HTML inside the WebForm, there won't be
any problem.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Paranoia is just a state of mind.
 
C

cmay

I was thinking about that after I posted.

So the problem is really that on pages where I have included JS files
that the script is running before the JS files that are needed have
been downloaded and parsed?
 

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,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top