When does script added with RegisterStartupScript() execute?

When does script added to the page with Page.ClientScript.RegisterStartupScript() actually run? MSDN states "when the page finishes loading but before the page’s OnLoad event is raised" but this isn’t much detail.

For example, can a script added with RegisterStartupScript assume the DOM tree has been built? Does the behaviour differ between different browser implementations and how?

29 thoughts on “When does script added with RegisterStartupScript() execute?”

  1. The startup scripts are added to the bottom of the markup. So they are processed automatically as the markup loads. I guess the exact implementation of this depends on the browser.

    Reply

Leave a Comment