ScriptManager::RegisterClientScriptBlock Method (Control, Type, String, String, Boolean)
Registers a client script block with the ScriptManager control for use with a control that is inside an UpdatePanel control, and then adds the script block to the page.
Assembly: System.Web.Extensions (in System.Web.Extensions.dll)
public: static void RegisterClientScriptBlock( Control^ control, Type^ type, String^ key, String^ script, bool addScriptTags )
Parameters
- control
- Type: System.Web.UI::Control
The control that is registering the client script block.
- type
- Type: System::Type
The type of the client script block. This parameter is usually specified by using the typeof operator (C#) or the GetType operator (Visual Basic) to retrieve the type of the control that is registering the script.
- key
- Type: System::String
A unique identifier for the script block.
- script
- Type: System::String
The script.
- addScriptTags
- Type: System::Boolean
true to enclose the script block in <script> and </script> tags; otherwise, false.
| Exception | Condition |
|---|---|
| ArgumentNullException | The client script block type is nullptr. - or - The control that is registering the script block is nullptr. |
| ArgumentException | The control that is registering the script block is not in the page's control tree. |
You use the RegisterClientScriptBlock method to register a client script block that is compatible with partial-page rendering and that has no Microsoft AJAX Library dependencies. Client script blocks that are registered by using this method are sent to the page only when control represents a control that is inside an UpdatePanel control that is being updated. To register a script block every time that an asynchronous postback occurs, use the RegisterClientScriptBlock(Page, Type, String, String, Boolean) overload of this method.
If you want to register a script block that does not pertain to partial-page updates, and if you want to register the script block only one time during initial page rendering, use the RegisterClientScriptBlock method of the ClientScriptManager class. You can get a reference to the ClientScriptManager object from the ClientScript property of the page.
If addScriptTags is true, the RegisterClientScriptBlock method adds <script> tags around the script block. Pass false if you want to create <script> tags yourself, such as when you want to set the attributes of specific <script> tags. If addScriptTags is false and the script parameter contains multiple script blocks, an exception is thrown.
The RegisterClientScriptBlock method adds a script block to the page after the opening <form> tag. The script blocks are not guaranteed to be output in the same order in which they are registered. If the order of the script blocks is important, concatenate your script blocks into a single string (for example, by using the StringBuilder object), and then register them as a single client script block.
<Contacts>
<Contact id="1"
Name="Aaber, Jesper"
Company="A. Data Corporation"
URL="http://www.adatum.com/"/>
<Contact id="2"
Name="Canel, Fabrice"
Company="Coho Winery"
URL="http://www.cohowinery.com/"/>
<Contact id="3"
Name="Heloo, Waleed"
Company="Contoso, Ltd"
URL="http://www.contoso.com/"/>
<Contact id="4"
Name="Rovik, Dag"
Company="Wingtip Toys"
URL="http://www.wingtiptoys.com/"/>
</Contacts>
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.