What is the difference between ClientScript.RegisterStartupScript() and ClientScript.RegisterClientScriptBlock()?
ClientScript. RegisterStartupScript for displaying alert messages. it works fine for the first message, however second message wont display. Though it passes through the code while debugging.
RegisterStartupScript(Control, Type, String, String, Boolean) Registers a startup script block for a control that is inside an UpdatePanel by using the ScriptManager control, and adds the script block to the page.
Is the only difference between the RegisterStartupScript and the RegisterClientScriptBlock is that RegisterStartupScript puts the javascript before the closing </form> tag of the page and RegisterClientScriptBlock puts it right after the starting <form> tag of the page?
ClientScript.RegisterStartupScript()
is for passing in a block of script which is automatically run at startup.
ClientScript.RegisterClientScriptBlock()
is just for registering a general method.
I think the technical difference is that the startup script is placed just before the </body>
so that it is executed as soon as possible after the page is loaded?
I have double checked this and it is is what I said.
http://msdn.microsoft.com/en-us/library/asz8zsxy.aspx ClientScript.RegisterStartupScript()
"The script block added by the RegisterStartupScript method executes when the page finishes loading but before the page's OnLoad event is raised."
http://msdn.microsoft.com/en-us/library/btf44dc9.aspx ClientScript.RegisterClientScriptBlock()
"The RegisterClientScriptBlock method adds a script block to the top of the rendered page."
ClientScript.RegisterStartupScript
places the script just before the closing </body>
tag while ClientScript.RegisterClientScriptBlock
places it in the beginning, just after the viewstate hidden fields.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With