System.Web.UI.ClientScriptManager Class

Defines methods for managing client scripts in Web applications.

See Also: ClientScriptManager Members


public sealed class ClientScriptManager


The System.Web.UI.ClientScriptManager class is used to manage client scripts and add them to Web applications. You can get a reference to the System.Web.UI.ClientScriptManager class from the Page.ClientScript property of the System.Web.UI.Page object.

You can add a client script to a Web page declaratively by including the script in the HTML markup of the page. However, there are situations when adding client script dynamically is needed. To add a script dynamically, use the erload:System.Web.UI.ClientScriptManager.RegisterClientScriptBlock method, the erload:System.Web.UI.ClientScriptManager.RegisterClientScriptInclude method, the erload:System.Web.UI.ClientScriptManager.RegisterStartupScript method, or the ClientScriptManager.RegisterOnSubmitStatement(Type, string, string) method, depending on when and how you want to add the script. For more information, see How to: Add Client Script Dynamically to ASP.NET Web Pages.

The System.Web.UI.ClientScriptManager class uniquely identifies scripts by a key string and a Type. Scripts with the same key and type are considered duplicates. Using the script type helps to avoid confusing similar scripts from different user controls that might be in use on the page.

The System.Web.UI.ClientScriptManager class can be used to invoke client callbacks in situations when it is desirable to run server code from the client without performing a postback. This is referred to as performing an out-of-band callback to the server. In a client callback, a client script function sends an asynchronous request to an ASP.NET Web page. The Web page runs a modified version of its normal life cycle to process the callback. Use the erload:System.Web.UI.ClientScriptManager.GetCallbackEventReference method to obtain a reference to a client function that, when invoked, initiates a client callback to a server event. For more information, see Client Callbacks Without Postbacks in ASP.NET Pages.


Script callbacks will not work in older browsers that do not support the Document Object Model (DOM), and they require that ECMAScript is enabled on the client. To check if the browser supports callbacks, use the System.Web.Configuration.HttpCapabilitiesBase.SupportsCallback property, which is accessible through the System.Web.HttpRequest.Browser property of the ASP.NET intrinsic System.Web.HttpContext.Request object.

Use the erload:System.Web.UI.ClientScriptManager.GetPostBackEventReference method and the ClientScriptManager.GetPostBackClientHyperlink(Control, string) method to define a client postback event. These methods enable client script functions, when invoked, to cause the server to post back to the page. A client postback event is different from a client callback in that the Web page completes a normal life cycle to process the client postback event.


If you are using a System.Web.UI.WebControls.Button control and the System.Web.UI.WebControls.Button.UseSubmitBehavior property is set to false, then you can use the erload:System.Web.UI.ClientScriptManager.GetPostBackEventReference method to return the client postback event for the System.Web.UI.WebControls.Button control.

The System.Web.UI.WebControls.Button.OnClientClick property of the System.Web.UI.WebControls.Button control, System.Web.UI.WebControls.ImageButton control, and System.Web.UI.WebControls.LinkButton control can be used to run client script.


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