System.Web.UI.ClientScriptManager.RegisterClientScriptBlock Method

Registers the client script with the System.Web.UI.Page object using a type, key, script literal, and Boolean value indicating whether to add script tags.

Syntax

public void RegisterClientScriptBlock (Type type, string key, string script, bool addScriptTags)

Parameters

type
The type of the client script to register.
key
The key of the client script to register.
script
The client script literal to register.
addScriptTags
A Boolean value indicating whether to add script tags.

Remarks

A client script is uniquely identified by its key and its type. Scripts with the same key and type are considered duplicates. Only one script with a given type and key pair can be registered with the page. Attempting to register a script that is already registered does not create a duplicate of the script.

Call the erload:System.Web.UI.ClientScriptManager.IsClientScriptBlockRegistered method to determine whether a client script with a given key and type pair is already registered. This lets you avoid unnecessarily attempting to add the script.

In this overload of the erload:System.Web.UI.ClientScriptManager.RegisterClientScriptBlock method, you can indicate whether the script provided in the script parameter is wrapped with a <script> element block by using the addScriptTags parameter. Setting addScriptTags to true indicates that script tags will be added automatically.

The erload:System.Web.UI.ClientScriptManager.RegisterClientScriptBlock method adds a script block to the top of the rendered page. The script blocks are not guaranteed to be output in the order they are registered. If the order of the script blocks is important, use a System.Text.StringBuilder object to gather the scripts together in a single string, and then register them all in a single client script block.

Requirements

Namespace: System.Web.UI
Assembly: System.Web (in System.Web.dll)
Assembly Versions: 2.0.0.0
Since: .NET 2.0