ScriptManager Class

Manages ASP.NET Ajax script libraries and script files, partial-page rendering, and client proxy class generation for Web and application services.

System.Object
  System.Web.UI.Control
    System.Web.UI.ScriptManager

Namespace:  System.Web.UI
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)

public class ScriptManager : Control, 
	IPostBackDataHandler, IPostBackEventHandler
<asp:ScriptManager />

The ScriptManager type exposes the following members.

  NameDescription
Public methodScriptManagerInitializes a new instance of the ScriptManager class.
Top

  NameDescription
Protected propertyAdapterGets the browser-specific adapter for the control. (Inherited from Control.)
Public propertyAjaxFrameworkAssemblyGets the Ajax framework assembly that components on the page use.
Public propertyAjaxFrameworkModeGets or sets a value that specifies how client scripts of the Microsoft Ajax client library will be included on the client.
Public propertyAllowCustomErrorsRedirectGets or sets a value that determines whether the custom errors section of the Web.config file is used during an error in an asynchronous postback.
Public propertyAppRelativeTemplateSourceDirectoryGets or sets the application-relative virtual directory of the Page or UserControl object that contains this control. (Inherited from Control.)
Public propertyAsyncPostBackErrorMessageGets or sets the error message that is sent to the client when an unhandled server exception occurs during an asynchronous postback.
Public propertyAsyncPostBackSourceElementIDGets the unique ID of the control that caused the asynchronous postback.
Public propertyAsyncPostBackTimeoutGets or sets a value that indicates the time, in seconds, before asynchronous postbacks time out if no response is received.
Public propertyAuthenticationServiceGets the AuthenticationServiceManager object that is associated with the current ScriptManager instance.
Public propertyBindingContainerInfrastructure. Gets the control that contains this control's data binding. (Inherited from Control.)
Protected propertyChildControlsCreatedGets a value that indicates whether the server control's child controls have been created. (Inherited from Control.)
Public propertyClientIDGets the control ID for HTML markup that is generated by ASP.NET. (Inherited from Control.)
Public propertyClientIDModeGets or sets the algorithm that is used to generate the value of the ClientID property. (Inherited from Control.)
Protected propertyClientIDSeparatorGets a character value representing the separator character used in the ClientID property. (Inherited from Control.)
Public propertyClientNavigateHandlerGets or sets the name of the method that handles the Sys.Application.navigate event on the client.
Public propertyCompositeScriptGets a reference to the composite script that supports the Web page.
Protected propertyContextGets the HttpContext object associated with the server control for the current Web request. (Inherited from Control.)
Public propertyControlsGets a ControlCollection object that represents the child controls for a specified server control in the UI hierarchy. (Inherited from Control.)
Public propertyDataItemContainerGets a reference to the naming container if the naming container implements IDataItemContainer. (Inherited from Control.)
Public propertyDataKeysContainerGets a reference to the naming container if the naming container implements IDataKeysControl. (Inherited from Control.)
Protected propertyDesignModeGets a value indicating whether a control is being used on a design surface. (Inherited from Control.)
Public propertyEmptyPageUrlGets or sets a URL to a blank Web page..
Public propertyEnableCdnDetermines whether the current page loads client script references from CDN (Content Delivery Network) paths.
Public propertyEnableHistoryGets or sets a value that indicates whether the Web page supports history point management.
Public propertyEnablePageMethodsGets or sets a value that indicates whether public static page methods in an ASP.NET page can be called from client script.
Public propertyEnablePartialRenderingGets or sets a value that enables partial rendering of a page, which in turn enables you to update regions of the page individually by using UpdatePanel controls.
Public propertyEnableScriptGlobalizationGets or sets a value that indicates whether the ScriptManager control renders script that supports parsing and formatting of culture-specific information.
Public propertyEnableScriptLocalizationGets or sets a value that indicates whether the ScriptManager control renders localized versions of script files.
Public propertyEnableSecureHistoryStateGets or sets a value that indicates whether to encrypt the history state string.
Public propertyEnableThemingGets or sets a value indicating whether themes apply to this control. (Inherited from Control.)
Public propertyEnableViewStateGets or sets a value indicating whether the server control persists its view state, and the view state of any child controls it contains, to the requesting client. (Inherited from Control.)
Protected propertyEventsGets a list of event handler delegates for the control. This property is read-only. (Inherited from Control.)
Protected propertyHasChildViewStateGets a value indicating whether the current server control's child controls have any saved view-state settings. (Inherited from Control.)
Public propertyIDGets or sets the programmatic identifier assigned to the server control. (Inherited from Control.)
Protected propertyIdSeparatorInfrastructure. Gets the character used to separate control identifiers. (Inherited from Control.)
Protected propertyIsChildControlStateClearedGets a value indicating whether controls contained within this control have control state. (Inherited from Control.)
Public propertyIsDebuggingEnabledGets a value that indicates whether the debug versions of client script libraries will be rendered.
Public propertyIsInAsyncPostBackGets a value that indicates whether the current postback is being executed in partial-rendering mode.
Public propertyIsNavigatingGets a value that indicates whether a Navigate event is currently being handled.
Protected propertyIsTrackingViewStateGets a value that indicates whether the server control is saving changes to its view state. (Inherited from Control.)
Protected propertyIsViewStateEnabledGets a value indicating whether view state is enabled for this control. (Inherited from Control.)
Public propertyLoadScriptsBeforeUIGets or sets a value that indicates whether scripts are loaded before or after markup for the page UI is loaded.
Protected propertyLoadViewStateByIDGets a value indicating whether the control participates in loading its view state by ID instead of index. (Inherited from Control.)
Public propertyNamingContainerGets a reference to the server control's naming container, which creates a unique namespace for differentiating between server controls with the same Control.ID property value. (Inherited from Control.)
Public propertyPageGets a reference to the Page instance that contains the server control. (Inherited from Control.)
Public propertyParentGets a reference to the server control's parent control in the page control hierarchy. (Inherited from Control.)
Public propertyProfileServiceGets the ProfileServiceManager object that is associated with the current ScriptManager instance.
Public propertyRenderingCompatibilityGets a value that specifies the ASP.NET version that rendered HTML will be compatible with. (Inherited from Control.)
Public propertyRoleServiceGets the RoleServiceManager object that is associated with the current ScriptManager instance.
Public propertyScriptModeGets or sets a value that specifies whether debug or release versions of client script libraries are rendered.
Public propertyScriptPath Obsolete. Gets or sets the root path of the location that is used to build the paths to ASP.NET Ajax and custom script files.
Public propertyStatic memberScriptResourceMappingGets a ScriptResourceMapping object.
Public propertyScriptsGets a ScriptReferenceCollection object that contains the ScriptReference objects, each of which represents a script file rendered to the client.
Public propertyServicesGets a ServiceReferenceCollection object that contains a ServiceReference object for each Web service that ASP.NET exposes on the client for Ajax functionality.
Public propertySiteGets information about the container that hosts the current control when rendered on a design surface. (Inherited from Control.)
Public propertySkinIDGets or sets the skin to apply to the control. (Inherited from Control.)
Public propertySupportsPartialRenderingGets a value that indicates whether the client supports partial-page rendering.
Public propertyTemplateControlGets or sets a reference to the template that contains this control. (Inherited from Control.)
Public propertyTemplateSourceDirectoryGets the virtual directory of the Page or UserControl that contains the current server control. (Inherited from Control.)
Public propertyUniqueIDGets the unique, hierarchically qualified identifier for the server control. (Inherited from Control.)
Protected propertyViewStateGets a dictionary of state information that allows you to save and restore the view state of a server control across multiple requests for the same page. (Inherited from Control.)
Protected propertyViewStateIgnoresCaseGets a value that indicates whether the StateBag object is case-insensitive. (Inherited from Control.)
Public propertyViewStateModeGets or sets the view-state mode of this control. (Inherited from Control.)
Public propertyVisibleOverrides the Visible property that is inherited from the base Control class to prevent setting this value. (Overrides Control.Visible.)
Top

  NameDescription
Protected methodAddedControlCalled after a child control is added to the Controls collection of the Control object. (Inherited from Control.)
Public methodAddHistoryPoint(NameValueCollection, String)Creates a history point and adds it to the browser's history stack, using the specified state data collection and state title.
Public methodAddHistoryPoint(String, String)Creates a history point and adds it to the browser's history stack, using the specified state key and state value.
Public methodAddHistoryPoint(String, String, String)Creates a history point and adds it to the browser's history stack, using the specified state key, state value, and state title.
Protected methodAddParsedSubObjectNotifies the server control that an element, either XML or HTML, was parsed, and adds the element to the server control's ControlCollection object. (Inherited from Control.)
Public methodApplyStyleSheetSkinApplies the style properties defined in the page style sheet to the control. (Inherited from Control.)
Protected methodBuildProfileTreeInfrastructure. Gathers information about the server control and delivers it to the Trace property to be displayed when tracing is enabled for the page. (Inherited from Control.)
Protected methodClearCachedClientIDInfrastructure. Sets the cached ClientID value to null. (Inherited from Control.)
Protected methodClearChildControlStateDeletes the control-state information for the server control's child controls. (Inherited from Control.)
Protected methodClearChildStateDeletes the view-state and control-state information for all the server control's child controls. (Inherited from Control.)
Protected methodClearChildViewStateDeletes the view-state information for all the server control's child controls. (Inherited from Control.)
Protected methodClearEffectiveClientIDModeInfrastructure. Sets the ClientIDMode property of the current control instance and of any child controls to Inherit. (Inherited from Control.)
Protected methodCreateChildControlsCalled by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering. (Inherited from Control.)
Protected methodCreateControlCollectionCreates a new ControlCollection object to hold the child controls (both literal and server) of the server control. (Inherited from Control.)
Public methodDataBind()Binds a data source to the invoked server control and all its child controls. (Inherited from Control.)
Protected methodDataBind(Boolean)Binds a data source to the invoked server control and all its child controls with an option to raise the DataBinding event. (Inherited from Control.)
Protected methodDataBindChildrenBinds a data source to the server control's child controls. (Inherited from Control.)
Public methodDisposeEnables a server control to perform final clean up before it is released from memory. (Inherited from Control.)
Protected methodEnsureChildControlsDetermines whether the server control contains child controls. If it does not, it creates child controls. (Inherited from Control.)
Protected methodEnsureIDCreates an identifier for controls that do not have an identifier assigned. (Inherited from Control.)
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodFindControl(String)Searches the current naming container for a server control with the specified id parameter. (Inherited from Control.)
Protected methodFindControl(String, Int32)Infrastructure. Searches the current naming container for a server control with the specified id and an integer, specified in the pathOffset parameter, which aids in the search. You should not override this version of the FindControl method. (Inherited from Control.)
Public methodFocusSets input focus to a control. (Inherited from Control.)
Public methodStatic memberGetCurrentGets the ScriptManager instance for a given Page object.
Protected methodGetDesignModeStateInfrastructure. Gets design-time data for a control. (Inherited from Control.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetRegisteredArrayDeclarationsRetrieves a read-only collection of ECMAScript (JavaScript) array declarations that were previously registered with the Page object.
Public methodGetRegisteredClientScriptBlocksRetrieves a read-only collection of client script blocks that were previously registered with the ScriptManager control.
Public methodGetRegisteredDisposeScriptsRetrieves a read-only collection of dispose scripts that were previously registered with the Page object.
Public methodGetRegisteredExpandoAttributesRetrieves a read-only collection of custom (expando) attributes that were previously registered with the Page object.
Public methodGetRegisteredHiddenFieldsRetrieves a read-only collection of hidden fields that were previously registered with the Page object.
Public methodGetRegisteredOnSubmitStatementsRetrieves a read-only collection of onsubmit statements that were previously registered with the Page object.
Public methodGetRegisteredStartupScriptsRetrieves a read-only collection of startup scripts that were previously registered with the Page object.
Public methodGetRouteUrl(Object)Gets the URL that corresponds to a set of route parameters. (Inherited from Control.)
Public methodGetRouteUrl(RouteValueDictionary)Gets the URL that corresponds to a set of route parameters. (Inherited from Control.)
Public methodGetRouteUrl(String, Object)Gets the URL that corresponds to a set of route parameters and a route name. (Inherited from Control.)
Public methodGetRouteUrl(String, RouteValueDictionary)Gets the URL that corresponds to a set of route parameters and a route name. (Inherited from Control.)
Public methodGetStateStringRetrieves a string that contains key/value pairs that represent the state of the Web page.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodGetUniqueIDRelativeToReturns the prefixed portion of the UniqueID property of the specified control. (Inherited from Control.)
Public methodHasControlsDetermines if the server control contains any child controls. (Inherited from Control.)
Protected methodHasEventsReturns a value indicating whether events are registered for the control or any child controls. (Inherited from Control.)
Protected methodIsLiteralContentInfrastructure. Determines if the server control holds only literal content. (Inherited from Control.)
Protected methodLoadControlStateRestores control-state information from a previous page request that was saved by the SaveControlState method. (Inherited from Control.)
Protected methodLoadPostDataReads form data that is posted from the browser to the server, and determines the source of the asynchronous postback.
Protected methodLoadViewStateRestores view-state information from a previous page request that was saved by the SaveViewState method. (Inherited from Control.)
Protected methodMapPathSecureRetrieves the physical path that a virtual path, either absolute or relative, maps to. (Inherited from Control.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodOnAsyncPostBackErrorRaises the AsyncPostBackError event.
Protected methodOnBubbleEventDetermines whether the event for the server control is passed up the page's UI server control hierarchy. (Inherited from Control.)
Protected methodOnDataBindingRaises the DataBinding event. (Inherited from Control.)
Protected methodOnInitRaises the Init event and makes sure that only one ScriptManager control exists on the page. (Overrides Control.OnInit(EventArgs).)
Protected methodOnLoadRaises the Load event. (Inherited from Control.)
Protected methodOnPreRenderRaises the PreRender event, and registers script files and services for partial-page updates. (Overrides Control.OnPreRender(EventArgs).)
Protected methodOnResolveCompositeScriptReferenceRaises the ResolveCompositeScriptReference event.
Protected methodOnResolveScriptReferenceRaises the ResolveScriptReference event for each script reference that is managed by the ScriptManager control
Protected methodOnUnloadRaises the Unload event. (Inherited from Control.)
Protected methodOpenFileGets a Stream used to read a file. (Inherited from Control.)
Protected methodRaiseBubbleEventAssigns any sources of the event and its information to the control's parent. (Inherited from Control.)
Protected methodRaisePostBackEventProcesses a postback event raised by the ScriptManager control and loads the history state of the Web page.
Protected methodRaisePostDataChangedEventRaises events for the ScriptManager control when it posts back to the server.
Public methodStatic memberRegisterArrayDeclaration(Control, String, String)Registers an ECMAScript (JavaScript) array declaration with the ScriptManager control for use with a control that is inside an UpdatePanel control, and adds the array to the page.
Public methodStatic memberRegisterArrayDeclaration(Page, String, String)Registers an ECMAScript (JavaScript) array declaration with the ScriptManager control for use with a control that is inside an UpdatePanel control, and adds the array to the page.
Public methodRegisterAsyncPostBackControlRegisters a control as a trigger for asynchronous postbacks.
Public methodStatic memberRegisterClientScriptBlock(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.
Public methodStatic memberRegisterClientScriptBlock(Page, 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.
Public methodStatic memberRegisterClientScriptInclude(Control, Type, String, String)Registers a client script file with the ScriptManager control for use with a control that is inside an UpdatePanel control, and then adds a script file reference to the page.
Public methodStatic memberRegisterClientScriptInclude(Page, Type, String, String)Registers client script with the ScriptManager control every time that an asynchronous postback occurs, and then adds a script file reference to the page.
Public methodStatic memberRegisterClientScriptResource(Control, Type, String)Registers the client script that is embedded in an assembly with the ScriptManager control for use with a control that is participating in partial-page rendering.
Public methodStatic memberRegisterClientScriptResource(Page, Type, String)Registers a client script file that is embedded in an assembly with the ScriptManager control every time that a postback occurs.
Public methodRegisterDataItem(Control, String)Sends custom data to a control during partial-page rendering.
Public methodRegisterDataItem(Control, String, Boolean)Sends custom data to a control during partial-page rendering, and indicates whether the data is in JavaScript Object Notation (JSON) format.
Public methodRegisterDisposeRegisters a dispose script for a control that is inside an UpdatePanel control. The script is executed when the UpdatePanel control is updated or deleted.
Public methodStatic memberRegisterExpandoAttributeRegisters a name/value pair with the ScriptManager control as a custom (expando) attribute of a specified control.
Public methodRegisterExtenderControl<TExtenderControl>Registers an extender control with the current ScriptManager instance.
Public methodStatic memberRegisterHiddenField(Control, String, String)Registers a hidden field with the ScriptManager control for a control that is inside an UpdatePanel control.
Public methodStatic memberRegisterHiddenField(Page, String, String)Registers a hidden field with the ScriptManager control during every asynchronous postback.
Public methodStatic memberRegisterOnSubmitStatement(Control, Type, String, String)Registers ECMAScript (JavaScript) code with the ScriptManager control for a control that is used with an UpdatePanel control that is executed when the form is submitted.
Public methodStatic memberRegisterOnSubmitStatement(Page, Type, String, String)Registers ECMAScript (JavaScript) code with the ScriptManager control for a control that is used with an UpdatePanel control that is executed when the form is submitted.
Public methodRegisterPostBackControlRegisters a control as a trigger for a postback. This method is used to configure postback controls inside an UpdatePanel control that would otherwise perform asynchronous postbacks.
Public methodRegisterScriptControl<TScriptControl>Registers a script control with the current ScriptManager instance.
Public methodRegisterScriptDescriptors(IExtenderControl)Calls back to an ExtenderControl class to return instance scripts that must be rendered to support the client object that represents a client control, component, or behavior.
Public methodRegisterScriptDescriptors(IScriptControl)Calls a ScriptControl class to return instance scripts that must be rendered to support the client object that represents a client control, component, or behavior.
Public methodStatic memberRegisterStartupScript(Control, Type, String, String, Boolean)Registers a startup script block for a control that is inside an UpdatePanel by using the ScriptManager control, and adds the script block to the page.
Public methodStatic memberRegisterStartupScript(Page, Type, String, String, Boolean)Registers a startup script block for every asynchronous postback with the ScriptManager control and adds the script block to the page.
Protected methodRemovedControlCalled after a child control is removed from the Controls collection of the Control object. (Inherited from Control.)
Protected methodRenderRenders the ScriptManager control's content to the browser by using the specified HtmlTextWriter object. (Overrides Control.Render(HtmlTextWriter).)
Protected methodRenderChildrenOutputs the content of a server control's children to a provided HtmlTextWriter object, which writes the content to be rendered on the client. (Inherited from Control.)
Public methodRenderControl(HtmlTextWriter)Outputs server control content to a provided HtmlTextWriter object and stores tracing information about the control if tracing is enabled. (Inherited from Control.)
Protected methodRenderControl(HtmlTextWriter, ControlAdapter)Outputs server control content to a provided HtmlTextWriter object using a provided ControlAdapter object. (Inherited from Control.)
Protected methodResolveAdapterGets the control adapter responsible for rendering the specified control. (Inherited from Control.)
Public methodResolveClientUrlGets a URL that can be used by the browser. (Inherited from Control.)
Public methodResolveUrlConverts a URL into one that is usable on the requesting client. (Inherited from Control.)
Protected methodSaveControlStateSaves any server control state changes that have occurred since the time the page was posted back to the server. (Inherited from Control.)
Protected methodSaveViewStateSaves any server control view-state changes that have occurred since the time the page was posted back to the server. (Inherited from Control.)
Protected methodSetDesignModeStateSets design-time data for a control. (Inherited from Control.)
Public methodSetFocus(Control)Sets the browser focus to the specified control.
Public methodSetFocus(String)Sets the browser focus to the control specified by ID.
Public methodSetRenderMethodDelegateInfrastructure. Assigns an event handler delegate to render the server control and its content into its parent control. (Inherited from Control.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Protected methodTrackViewStateCauses tracking of view-state changes to the server control so they can be stored in the server control's StateBag object. This object is accessible through the Control.ViewState property. (Inherited from Control.)
Top

  NameDescription
Public eventAsyncPostBackErrorOccurs when there is a page error during an asynchronous postback.
Public eventDataBindingOccurs when the server control binds to a data source. (Inherited from Control.)
Public eventDisposedOccurs when a server control is released from memory, which is the last stage of the server control lifecycle when an ASP.NET page is requested. (Inherited from Control.)
Public eventInitOccurs when the server control is initialized, which is the first step in its lifecycle. (Inherited from Control.)
Public eventLoadOccurs when the server control is loaded into the Page object. (Inherited from Control.)
Public eventNavigateOccurs when the user clicks the browser's Back or Forward button.
Public eventPreRenderOccurs after the Control object is loaded but prior to rendering. (Inherited from Control.)
Public eventResolveCompositeScriptReferenceOccurs when a composite script is registered with the ScriptManager control.
Public eventResolveScriptReferenceOccurs when a member of the Scripts collection is registered with the ScriptManager control.
Public eventUnloadOccurs when the server control is unloaded from memory. (Inherited from Control.)
Top

  NameDescription
Public Extension MethodFindDataSourceControlReturns the data source that is associated with the data control for the specified control. (Defined by DynamicDataExtensions.)
Public Extension MethodFindFieldTemplateReturns the field template for the specified column in the specified control's naming container. (Defined by DynamicDataExtensions.)
Public Extension MethodFindMetaTableReturns the metatable object for the containing data control. (Defined by DynamicDataExtensions.)
Top

  NameDescription
Explicit interface implemetationPrivate propertyIControlBuilderAccessor.ControlBuilderFor a description of this member, see IControlBuilderAccessor.ControlBuilder. (Inherited from Control.)
Explicit interface implemetationPrivate methodIControlDesignerAccessor.GetDesignModeStateFor a description of this member, see IControlDesignerAccessor.GetDesignModeState. (Inherited from Control.)
Explicit interface implemetationPrivate methodIControlDesignerAccessor.SetDesignModeStateFor a description of this member, see IControlDesignerAccessor.SetDesignModeState. (Inherited from Control.)
Explicit interface implemetationPrivate methodIControlDesignerAccessor.SetOwnerControlInfrastructure. For a description of this member, see IControlDesignerAccessor.SetOwnerControl. (Inherited from Control.)
Explicit interface implemetationPrivate propertyIControlDesignerAccessor.UserDataFor a description of this member, see IControlDesignerAccessor.UserData. (Inherited from Control.)
Explicit interface implemetationPrivate propertyIDataBindingsAccessor.DataBindingsFor a description of this member, see IDataBindingsAccessor.DataBindings. (Inherited from Control.)
Explicit interface implemetationPrivate propertyIDataBindingsAccessor.HasDataBindingsFor a description of this member, see IDataBindingsAccessor.HasDataBindings. (Inherited from Control.)
Explicit interface implemetationPrivate propertyIExpressionsAccessor.ExpressionsFor a description of this member, see IExpressionsAccessor.Expressions. (Inherited from Control.)
Explicit interface implemetationPrivate propertyIExpressionsAccessor.HasExpressionsFor a description of this member, see IExpressionsAccessor.HasExpressions. (Inherited from Control.)
Explicit interface implemetationPrivate methodIParserAccessor.AddParsedSubObjectFor a description of this member, see IParserAccessor.AddParsedSubObject. (Inherited from Control.)
Explicit interface implemetationPrivate methodIPostBackDataHandler.LoadPostDataFor a description of this member, see IPostBackDataHandler.LoadPostData.
Explicit interface implemetationPrivate methodIPostBackDataHandler.RaisePostDataChangedEventFor a description of this member, see IPostBackDataHandler.RaisePostDataChangedEvent.
Explicit interface implemetationPrivate methodIPostBackEventHandler.RaisePostBackEventEnables the ScriptManager control to process a postback event and load the history state of the Web page.
Top

In this topic:

Introduction

The ScriptManager control is central to Ajax functionality in ASP.NET. The control manages all ASP.NET Ajax resources on a page. This includes downloading Microsoft Ajax Library scripts to the browser and coordinating partial-page updates that are enabled by using UpdatePanel controls. In addition, the ScriptManager control enables you to do the following:

  • Register script that is compatible with partial-page updates. In order to manage dependencies between your script and the core library, any script that you register is loaded after the Microsoft Ajax Library script.

  • Specify whether release or debug scripts are sent to the browser.

  • Provide access to Web service methods from script by registering Web services with the ScriptManager control.

  • Provide access to ASP.NET authentication, role, and profile application services from client script by registering these services with the ScriptManager control.

  • Enable culture-specific display of ECMAScript (JavaScript) Date, Number, and String functions in the browser.

  • Access localization resources for embedded script files or for stand-alone script files by using the ResourceUICultures property of the ScriptReference control.

  • Register server controls that implement the IExtenderControl or IScriptControl interfaces with the ScriptManager control so that script required by client components and behaviors is rendered.

Partial-Page Rendering

The ability of an ASP.NET page to support partial-page rendering is controlled by the following factors:

You can override the value of the EnablePartialRendering property at run time during or before the page's Init event. If you try to change this property after the page's Init event has occurred, an InvalidOperationException exception is thrown.

When partial-page rendering is supported, the ScriptManager control renders script to enable asynchronous postbacks and partial-page updates. The regions of the page to be updated are designated by using UpdatePanel controls. The ScriptManager control handles the asynchronous postbacks and refreshes only the regions of the page that have to be updated. For more information about partial-page rendering, see Partial-Page Rendering Overview. For more information about the conditions that cause an update, see UpdatePanel Control Overview.

Using the ScriptManager Control with Master Pages, User Controls, and Other Child Components

A page can contain only one ScriptManager control in its hierarchy. To register services and scripts for nested pages, user controls, or components when the parent page already has a ScriptManager control, use the ScriptManagerProxy control. For more information, see Using the ASP.NET UpdatePanel Control with Master Pages

Script Management and Registration

The ScriptManager control enables you to register script that is then rendered as part of the page. The ScriptManager control registration methods can be broken into the following three categories:

  • Registration methods that guarantee that script dependencies on the Microsoft Ajax Library are maintained.

  • Registration methods that are not dependent on the Microsoft Ajax Library, but that are compatible with UpdatePanel controls.

  • Registration methods that support working with UpdatePanel controls.

For more information about how to create and use Ajax script in ASP.NET, see Creating Custom Client Script by Using the Microsoft Ajax Library.

Registering Script That Is Dependent on the Microsoft Ajax Library

You can use the following methods to register script files in a way that guarantees that any dependencies on the Microsoft Ajax Library are maintained. 

Method

Definition

RegisterScriptControl<TScriptControl>

Registers a server control that implements the IScriptControl interface that is used to define a Sys.Component client object. The ScriptManager control renders script that supports the client object.

RegisterExtenderControl<TExtenderControl>

Registers a server control that implements the IExtenderControl interface that is used to define a Sys.UI.Behavior client object. The ScriptManager control renders script that supports the client object.

Registering Partial-Page Update Compatible Scripts

You can use the following methods to register script files that are not dependent on the Microsoft Ajax Library but that are compatible with UpdatePanel controls. These methods correspond to similar methods of the ClientScriptManager control. If you are rendering script for use inside an UpdatePanel control, make sure that you call the methods of the ScriptManager control.

Method

Definition

RegisterArrayDeclaration

Adds a value to a JavaScript array. If the array does not exist, it is created.

RegisterClientScriptBlock

Renders a script element after the page's opening <form> tag. The script is specified as a string parameter.

RegisterClientScriptInclude

Renders a script element after the page's opening <form> tag. The script content is specified by setting the src attribute to a URL that points to a script file.

RegisterClientScriptResource

Renders a script element after the page's opening <form> tag. The script content is specified with a resource name in an assembly. The src attribute is automatically populated with a URL by a call to an HTTP handler that retrieves the named script from the assembly.

RegisterExpandoAttribute

Renders a custom name/value attribute pair (an expando) in the markup for a specified control.

RegisterHiddenField

Renders a hidden field.

RegisterOnSubmitStatement

Registers a script that is executed in response to the form element's submit event. The onSubmit attribute references the specified script.

RegisterStartupScript

Renders a startup script block just before the page's closing </form> tag. The script to render is specified as a string parameter.

When you register methods, you specify a type/key pair for that script. If a script with the same type/key pair is already registered, a new script is not registered. Similarly, if you register a script with a type/resource name pair that already exists, the script element that references the resource is not added again. When you register an expando attribute of a previously registered attribute, an exception is thrown. Duplicate registration of array values is allowed.

When you call the RegisterClientScriptInclude or the RegisterClientScriptResource method, avoid registering script that executes inline functions. Instead, register script that contains function definitions like event handlers or custom class definitions for your application.

Registration Methods for UpdatePanel Controls

You can use the following methods to customize partial-page updates when you use UpdatePanel controls.

Method

Definition

RegisterAsyncPostBackControl

Registers a control as a trigger for asynchronous postbacks.

RegisterDataItem

Sends custom data to controls during partial-page rendering.

RegisterDispose

Registers a dispose script for a control that is inside an UpdatePanel control. The script is executed when the UpdatePanel control is updated or deleted. The dispose method is used for client components that are part of the Microsoft Ajax Library and that have to free resources when a component is no longer used.

RegisterPostBackControl

Registers a control as a trigger for a full postback. This method is used for controls inside an UpdatePanel control that would otherwise perform asynchronous postbacks.

Web Service References

You can register a Web service to be called from client script by creating a ServiceReference object and adding it to the Services collection of the ScriptManager control. ASP.NET generates a client proxy object for each ServiceReference object in the Services collection. You can programmatically add ServiceReference objects to the Services collection to register Web services at run time.

For more information about how to access Web services in script, see Exposing Web Services to Client Script in ASP.NET AJAX and Calling Web Services from Client Script in ASP.NET AJAX.

Localization

The ScriptManager control generates references in the rendered page that point to the appropriate localized script files, which are either script files embedded in assemblies or stand-alone script files.

When the EnableScriptLocalization property is set to true, the ScriptManager control retrieves localized resources (such as localized strings) for the current culture, if they exist. The ScriptManager control provides the following functionality for using localized resources:

  • Script files that are embedded in an assembly. The ScriptManager control determines which culture-specific or fallback-culture script file to send to the browser. It does this by using the culture-specific NeutralResourcesLanguageAttribute assembly attribute, the resources packaged with the assembly, and the UI culture of the browser (if any).

  • Stand-alone script files. The ScriptManager control defines the list of UI cultures that are supported by using the ResourceUICultures property of the ScriptReference object.

  • In debug mode. The ScriptManager control tries to render a culture-specific script file that contains debug information. For example, if the page is in debug mode and the current culture is set to en-MX, the control renders a script file that has a name such as scriptname.en-MX.debug.js, if the file exists. If the file does not exist, the debug file for the appropriate fallback culture is rendered

For more information about how to localize resources, see Localizing Resources for Component Libraries Overview.

Error Handling

When a page error occurs during asynchronous postbacks, the AsyncPostBackError event is raised. The way in which errors on the server are sent to the client depends on the AllowCustomErrorsRedirect property, the AsyncPostBackErrorMessage property, and the custom errors section of the Web.config file. For more information, see Customizing Error Handling for ASP.NET UpdatePanel Controls.

Declarative Syntax

<asp:ScriptManager
    AllowCustomErrorsRedirect="True|False"
    AsyncPostBackErrorMessage="string"
    AsyncPostBackTimeout="integer"
    AuthenticationService-Path="uri"
    EnablePageMethods="True|False"
    EnablePartialRendering="True|False"
    EnableScriptGlobalization="True|False"
    EnableScriptLocalization="True|False"
    EnableTheming="True|False"
    EnableViewState="True|False"
    ID="string"
    LoadScriptsBeforeUI="True|False"
    OnAsyncPostBackError="AsyncPostBackError event handler"
    OnDataBinding="DataBinding event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnLoad="Load event handler"
    OnPreRender="PreRender event handler"
    OnResolveScriptReference="ResolveScriptReference event handler"
    OnUnload="Unload event handler"
    ProfileService-LoadProperties="string"
    ProfileService-Path="uri"
    RoleService-LoadRoles="True|False"
    RoleService-Path="uri"
    runat="server"
    ScriptMode="Auto|Inherit|Debug|Release"
    ScriptPath="string"
    SkinID="string"
    SupportsPartialRendering="True|False"
    Visible="True|False"
>
        <AuthenticationService
            Path="uri"
        />
        <ProfileService
            LoadProperties="string"
            Path="uri"
        />
        <RoleService
            LoadRoles="True|False"
            Path="uri"
        />
        <Scripts>
            <asp:ScriptReference
                Assembly="string"
                IgnoreScriptPath="True|False"
                Name="string"
                NotifyScriptLoaded="True|False"
                Path="string"
                ResourceUICultures="string"
                ScriptMode="Auto|Debug|Inherit|Release"
            />
        </Scripts>
        <Services>
            <asp:ServiceReference
                InlineScript="True|False"
                Path="string"
            />
        </Services>
</asp:ScriptManager>

The following examples show different scenarios for using the ScriptManager control.

Enabling Partial-Page Updates

The following example shows how to use the ScriptManager control to enable partial-page updates. In this example, a Calendar and a DropDownList control are inside an UpdatePanel control. By default, the value of the UpdateMode property is Always, and the value of the ChildrenAsTriggers property is true. Therefore, child controls of the panel cause an asynchronous postback.



<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    void DropDownSelection_Change(Object sender, EventArgs e)
    {
        Calendar1.DayStyle.BackColor =
            System.Drawing.Color.FromName(ColorList.SelectedItem.Value);
    }

    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        SelectedDate.Text = 
            Calendar1.SelectedDate.ToString();
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>UpdatePanel Example</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" 
                               runat="server" />
            <asp:UpdatePanel ID="UpdatePanel1"
                             runat="server">
                <ContentTemplate>
                    <asp:Calendar ID="Calendar1" 
                                  ShowTitle="True"
                                  OnSelectionChanged="Calendar1_SelectionChanged"
                                  runat="server" />
                    <div>
                        Background:
                        <br />
                        <asp:DropDownList ID="ColorList" 
                                          AutoPostBack="True" 
                                          OnSelectedIndexChanged="DropDownSelection_Change"
                                          runat="server">
                            <asp:ListItem Selected="True" Value="White"> 
                            White </asp:ListItem>
                            <asp:ListItem Value="Silver"> 
                            Silver </asp:ListItem>
                            <asp:ListItem Value="DarkGray"> 
                            Dark Gray </asp:ListItem>
                            <asp:ListItem Value="Khaki"> 
                            Khaki </asp:ListItem>
                            <asp:ListItem Value="DarkKhaki"> D
                            ark Khaki </asp:ListItem>
                        </asp:DropDownList>
                    </div>
                    <br />
                    Selected date:
                    <asp:Label ID="SelectedDate" 
                               runat="server">None.</asp:Label>
                </ContentTemplate>
            </asp:UpdatePanel>
            <br />
        </div>
    </form>
</body>
</html>


Handling Partial-Page Update Errors and Registering Script

The following example shows how to provide custom error handling during partial-page updates. By default, when an error occurs during partial-page updates, a JavaScript message box is displayed. This example demonstrates how to use custom error handling by providing a handler for the AsyncPostBackError event, and by setting the AsyncPostBackErrorMessage property in the event handler. You can also set the AllowCustomErrorsRedirect property to specify how the custom errors section of the Web.config file is used when an error occurs during partial-page updates. In this example, the default value of the AllowCustomErrorsRedirect property is used. This means that if the Web.config file contains a customErrors element, that element determines how errors are displayed. For more information, see customErrors Element (ASP.NET Settings Schema).


<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            int a = Int32.Parse(TextBox1.Text);
            int b = Int32.Parse(TextBox2.Text);
            int res = a / b;
            Label1.Text = res.ToString();
        }
        catch (Exception ex)
        {
            if (TextBox1.Text.Length > 0 && TextBox2.Text.Length > 0)
            {
                ex.Data["ExtraInfo"] = " You can't divide " +
                    TextBox1.Text + " by " + TextBox2.Text + ".";
            }
            throw ex;
        }
    }

    protected void ScriptManager1_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)
    {
        if (e.Exception.Data["ExtraInfo"] != null)
        {
            ScriptManager1.AsyncPostBackErrorMessage =
                e.Exception.Message +
                e.Exception.Data["ExtraInfo"].ToString();
        }
        else
        {
            ScriptManager1.AsyncPostBackErrorMessage =
                "An unspecified error occurred.";
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>UpdatePanel Error Handling Example</title>
    <style type="text/css">
    #UpdatePanel1 {
      width: 200px; height: 50px;
      border: solid 1px gray;
    }
    #AlertDiv{
    left: 40%; top: 40%;
    position: absolute; width: 200px;
    padding: 12px; 
    border: #000000 1px solid;
    background-color: white; 
    text-align: left;
    visibility: hidden;
    z-index: 99;
    }
    #AlertButtons{
    position: absolute; right: 5%; bottom: 5%;
    }
    </style>
</head>
<body id="bodytag">
    <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" 
            OnAsyncPostBackError="ScriptManager1_AsyncPostBackError" runat="server" >
            <Scripts>
            <asp:ScriptReference Path="ErrorHandling.js" />
            </Scripts>
            </asp:ScriptManager>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Width="39px"></asp:TextBox>
                    /
                    <asp:TextBox ID="TextBox2" runat="server" Width="39px"></asp:TextBox>
                    =
                    <asp:Label ID="Label1" runat="server"></asp:Label><br />
                    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="calculate" />
                </ContentTemplate>
            </asp:UpdatePanel>
            <div id="AlertDiv">
                <div id="AlertMessage">
                </div>
                <br />
                <div id="AlertButtons">
                    <input id="OKButton" type="button" value="OK" runat="server" onclick="ClearErrorState()" />
                </div>
            </div>
        </div>
    </form>
</body>
</html>


Globalizing the Date and Time That Are Displayed in the Browser

The following example shows how to set the EnableScriptGlobalization property so that client script can display a culture-specific date and time in the browser. In the example, the Culture attribute of the @ Page directive is set to auto. As a result, the first language that is specified in the current browser settings determines the culture and UI culture for the page. For more information, see How to: Set the Culture and UI Culture for ASP.NET Web Page Globalization.


<%@ Page Language="C#" Culture="auto" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Globalization Example</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" EnableScriptGlobalization="true" runat="server">
        </asp:ScriptManager>
        <script type="text/javascript">
        function pageLoad() {
          Sys.UI.DomEvent.addHandler($get("Button1"), "click", formatDate);
        }
        function formatDate() {
          var d = new Date();
          try {
            $get('Label1').innerHTML = d.localeFormat("dddd, dd MMMM yyyy HH:mm:ss");
          }
          catch(e) {
            alert("Error:" + e.message);
          }
        }
        </script>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional">
        <ContentTemplate>
        <asp:Panel ID="Panel1" runat="server" GroupingText="Update Panel">
        <asp:Button ID="Button1" runat="server" Text="Display Date" />

        <br />

        <asp:Label ID="Label1" runat="server"></asp:Label>
        </asp:Panel>
        </ContentTemplate>
        </asp:UpdatePanel>
    </form>
</body>
</html>


.NET Framework

Supported in: 4, 3.5

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft