Controlling where a script is placed

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.
 
B

bruce barker

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)
 
H

Hans Kesting

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
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top