Saturday, January 1, 2011

RegisterClientScriptBlock Vs RegisterStartupScript

Hi Guys!

Since few month ago I very confused about RegisterClientScriptBlock and RegisterStartupScript, Where i used them and what is the difference between. These thing cleared while I was reading a book of Appress for my exams. Anyways, both Method exists in ScripManager Class in .Net Framework Ajax Extensions Library, and both have same signature and same functionality to register client script into web browser but slightly difference between these functionality. I will try to explain difference.

RegisterClientScriptBlock:

RegisterClientScriptBlock Generate script just after start Forms tag, Sever conrols and other HTML controls render after it(excepted viewstate).

Above code result shown below screenshot

RegisterStartupScript:

RegisterStartupScript generate JavaScript block after rendering all controls and just before End of Forms tag.

Above code result shown below screenshot

Summary,

Whenever we called RegisterClientScriptBlock or RegisterStartupScript both registered JavaScript into web browsers. RegisterStartupScript used when we need to called HTML tag in JavaScript and perform some action into or by that HTML tag. While we will use RegisterClientScriptBlock when no need to any HTML tag. Always remember one thing HTML and JavaScript Interpreted line by line.

No comments:

Post a Comment