Add jscript at the end (with ClientScript.RegisterClientScriptBlock) ?

S

Stan SR

Hi,
I need to place some javascript code at the end of my aspx page.
How can I do that using the ClientScript.RegisterClientScriptBlock ?

Thanks

Stan
 
L

Laurent Bugnion, GalaSoft

Hi,

Stan said:
Hi,
I need to place some javascript code at the end of my aspx page.
How can I do that using the ClientScript.RegisterClientScriptBlock ?

Thanks

Stan

AFAIK, you cannot specify the location of the script block using the
ClientScript manager.

If you want the script to be executed only when the page is fully
loaded, pack your code in a function, use ClientScript to register the
script, and add a "onload" event to the "body" tag, to execute the
function. The "onload" event is called when the whole page is parsed and
rendered.

If you have a reason to place the script at a specific place, you can
override the "Render" method in the Page class, and instead of calling
"base.Render( writer );", you render all the controls in the children
controls collection using the RenderControl method. When all the
controls have been rendered, add your script tag using the
HtmlTextWriter provided to the Render method.

HTH,
Laurent
 
B

bruce barker \(sqlwork.com\)

RegisterClientScript block renders the javascript after the <form>.
RegisterStartupScript renders before </form>.

-- bruce (sqlwork.com)
 
L

Laurent Bugnion, GalaSoft

Hi,
RegisterClientScript block renders the javascript after the <form>.
RegisterStartupScript renders before </form>.

-- bruce (sqlwork.com)

Mmmh right. That makes more sense than my complicated proposal :)

Laurent
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top