ClientScriptManager.RegisterClientScriptBlock Method (Type, String, String, Boolean)
Registers the client script with the Page object using a type, key, script literal, and Boolean value indicating whether to add script tags.
Assembly: System.Web (in System.Web.dll)
member RegisterClientScriptBlock : type:Type * key:string * script:string * addScriptTags:bool -> unit
The client script block type is a null reference (Nothing in Visual Basic).
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 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 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 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 StringBuilder object to gather the scripts together in a single string, and then register them all in a single client script block.
The following code example demonstrates the use of the RegisterClientScriptBlock method. Note that the addScriptTags parameter is set to true so the beginning and closing script tags are not included with the script parameter.
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.