Difference Between RegisterStartupScript And RegisterClientScriptBlock


RegisterClientScriptBlock & RegisterStartupScript appends the javascript code from code behind. This is because, sometimes we may have to append the javascript code dynamically. For example, database value like ProjectID may be required for the execution of the JavaScript.




RegisterStartupScript will append the javascript code just above the closing form tag. The javascript code will get executed only after complete rendering of the View. Hence if the javascript is based on any controls, the code will be executed without having any error. For example, if the javascript fetches value of any label on View, it will be readly available. The following code is used for appending the javascript code by using RegisterStartupScript.

Difference Between RegisterStartupScript And RegisterClientScriptBlock, RegisterStartupScript And RegisterClientScriptBlock, RegisterStartupScript VS RegisterClientScriptBlock, Javascript, Jquery, Asp.Net, RegisterStartupScript, RegisterClientScriptBlock


RegisterClientScriptBlock appends the javascript code just after the starting form tag. Here javascript will be executed before the controls get rendered. Hence none of the controls will be available for the execution of the javascript. If the javascript code fetches any lable value, it will not be available. The following code is used for appending the javascript code by using RegisterClientScriptBlock.


Difference Between RegisterStartupScript And RegisterClientScriptBlock, RegisterStartupScript And RegisterClientScriptBlock, RegisterStartupScript VS RegisterClientScriptBlock, Javascript, Jquery, Asp.Net, RegisterStartupScript, RegisterClientScriptBlock