Click here to Skip to main content
16,021,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Differences between RegisterStartupScript and RegisterClientScriptBlock?
Posted

RegisterStartupScript Places the script at the bottom of the asp.net page instead of at the top.
It registers the startup script with the Page object using a type, a key, a script literal, and a Boolean value indicating whether to add script tags.

RegisterClientScriptBlock inserts script immediately below the opening tag of the Page . means after <form> tag.
It registers the client script with the Page object using a type, key, script literal, and Boolean value indicating whether to add script tags.

Similarities:
Both RegisterStartupScript and RegisterClientScriptBlock is uniquely identified by its key and its type.
Scripts with the same key and type are considered duplicates. Only one script with a given type and key pair can be registered with the page. Attempting to register a script that is already registered does not create a duplicate of the script.
 
Share this answer
 
RegisterClientScriptBlock method adds a script block to the top of the rendered page where as RegisterStartupScript method adds a script block to the end of the rendered page. It executes when the page finishes loading but before the page's OnLoad event is raised.

Refer:
MSDN: RegisterClientScriptBlock Method[^]
MSDN: RegisterStartupScript Method[^]
 
Share this answer
 
Comments
Vani Kulkarni 9-Jul-12 7:29am    
My 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900