Controlling where a script is placed

  • Thread starter Thread starter Nathan Sokalski
  • Start date Start date
N

Nathan Sokalski

We all know that Page.ClientScript has several ways to register scripts, but
none of them seem to do what they should. For example, how do I put at
script in the <head> section using Page.ClientScript? Shouldn't stuff added
using RegisterStartupScript be executed before stuff added using
RegisterClientScriptBlock? Can someone give me a summary or good reference
as to where the different methods actually put the scripts? Thanks.
 
its pretty simple. RegisterScriptBlock, goes right after the <form>.
RegisterStartupScript goes right before the </form>. there is no support
for placing script in the <head>.

-- bruce (sqlwork.com)
 
Nathan Sokalski laid this down on his screen :
We all know that Page.ClientScript has several ways to register scripts, but
none of them seem to do what they should. For example, how do I put at script
in the <head> section using Page.ClientScript? Shouldn't stuff added using
RegisterStartupScript be executed before stuff added using
RegisterClientScriptBlock? Can someone give me a summary or good reference as
to where the different methods actually put the scripts? Thanks.

A startup-script should fire on startup and be able to access all
controls on the page (if required), so it must be fired *after* all
controls on the page are loaded. That is why it is rendered ar the
*end* of the page, instead of (as you would expect) at the start of the
page.

RegisterClientScript is meant for blocks of javascript that should be
"available" when needed, therefore it is rendered first on the page.

Hans Kesting
 
Back
Top