Adding Client-Side Script Blocks with RegisterStartupScript() and RegisterClientScriptBlock()

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 </form> tag).

From http://msdn.microsoft.com/en-us/library/aa478975.aspx

2 thoughts on “Adding Client-Side Script Blocks with RegisterStartupScript() and RegisterClientScriptBlock()

  1. My family every time say that I am wasting my time here at web,
    except I know I am getting knowledge every day by reading thes nice articles.

  2. Продам базу данных по предприятиям и организациям г. Москва.
    В базе содержится информация: область деятельности, название
    организации, телефон/факс, email, адрес.
    Возможность выгрузки только email-адресов.
    Количество: 43,000 шт.
    Дата сбора: 08 ноября 2014 г.
    Цена-самая низкая в сети!
    ICQ: 658548888.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s