Friday, September 26, 2008

What is the difference between RegisterClientScriptBlock and RegisterStartupScript?

The RegisterClientScriptBlock method inserts the client-side script immediately below the opening tag of the Page object’s [form runat=”server”] element. The code cannot access any of the form’s elements because, at that time, the elements haven’t been instantiated yet. This explains why hdnView variable had a null value in my case. The RegisterStartupScript method inserts the specified client-side script just before the closing tag of the Page object’s [form runat=”server”] element. The code can access any of the form’s elements because, at that time, the elements have been instantiated. The choice of which method to use really depends on the “order” in which you want your script to be run by the browser when rendering the page.

(http://treasure4developer.wordpress.com/2008/02/05/difference-between-registerclientscriptblock-and-registerstartupscript/)

RegisterClientScriptBlock is meant for functions that should
be "available" to the page. For this they are rendered at the start
of the HTML file.

RegisterStartupScript is meant for commands that should execute on
page load (at the client), so tha page needs to be available for the
script. This script is rendered at the end of the HTML file.

(http://bytes.com/forum/thread278475.html)

No comments: