Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ClientScript.RegisterStartupScript()

Tags:

c#

What is the difference between ClientScript.RegisterStartupScript() and ClientScript.RegisterClientScriptBlock()?

like image 347
Rupa Mistry Avatar asked Dec 23 '10 15:12

Rupa Mistry


People also ask

What is the use of Page ClientScript RegisterStartupScript?

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.

What is the use of RegisterStartupScript?

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.

What is the difference between RegisterClientScriptBlock and RegisterStartupScript?

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?


2 Answers

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?

Update

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

like image 198
rtpHarry Avatar answered Oct 16 '22 03:10

rtpHarry


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.

like image 36
Darin Dimitrov Avatar answered Oct 16 '22 03:10

Darin Dimitrov