The System.Web.UI.Page class contains two methods for emitting client-side script code into the HTML rendered by the ASP.NET Web page:
- RegisterStartupScript(key, script)
- RegisterClientScriptBlock(key, script)
Both of these methods take two strings as input. The second parameter, script, is the client-side script—including the opening and closing
<script> tags—to insert into the page. The first parameter, key, serves as a unique identifier for the inserted client-side script.
The only difference between these two methods is where each one emits the script block.
RegisterClientScriptBlock() emits the script block at the beginning of the Web Form (right after the
<form runat="server"> tag), while
RegisterStartupScript() emits the script block at the end of the Web Form (right before the