Documentation for: ASP.NET Ajax Version 1.0

This documentation is for a previous version. For the current released version, see the ASP.NET Ajax documentation on MSDN.

 

 

 

 

 

 

 

Skip Navigation Links.
ScriptManager Class
ScriptManager Constructor
AllowCustomErrorsRedirect Property
AsyncPostBackError Event
AsyncPostBackErrorMessage Property
AsyncPostBackSourceElementID Property
AsyncPostBackTimeout Property
AuthenticationService Property
EnablePageMethods Property
EnablePartialRendering Property
EnableScriptGlobalization Property
EnableScriptLocalization Property
GetCurrent Method (page)
IsDebuggingEnabled Property
IsInAsyncPostBack Property
LoadPostData Method (postDataKey, postCollection)
LoadScriptsBeforeUI Property
OnAsyncPostBackError Method (e)
OnInit Method (e)
OnPreRender Method (e)
OnResolveScriptReference Method (e)
ProfileService Property
RaisePostDataChangedEvent Method
RegisterArrayDeclaration Method
RegisterArrayDeclaration Method (control, arrayName, arrayValue)
RegisterArrayDeclaration Method (page, arrayName, arrayValue)
RegisterAsyncPostBackControl Method (control)
RegisterClientScriptBlock Method
RegisterClientScriptBlock Method (control, type, key, script, addScriptTags)
RegisterClientScriptBlock Method (page, type, key, script, addScriptTags)
RegisterClientScriptInclude Method
RegisterClientScriptInclude Method (control, type, key, url)
RegisterClientScriptInclude Method (page, type, key, url)
RegisterClientScriptResource Method
RegisterClientScriptResource Method (control, type, resourceName)
RegisterClientScriptResource Method (page, type, resourceName)
RegisterDataItem Method
RegisterDataItem Method (control, dataItem)
RegisterDataItem Method (control, dataItem, isJsonSerialized)
RegisterDispose Method (control, disposeScript)
RegisterExpandoAttribute Method (control, controlId, attributeName, attributeValue, encode)
RegisterExtenderControl Method (extenderControl, targetControl)
RegisterHiddenField Method
RegisterHiddenField Method (control, hiddenFieldName, hiddenFieldInitialValue)
RegisterHiddenField Method (page, hiddenFieldName, hiddenFieldInitialValue)
RegisterOnSubmitStatement Method
RegisterOnSubmitStatement Method (control, type, key, script)
RegisterOnSubmitStatement Method (page, type, key, script)
RegisterPostBackControl Method (control)
RegisterScriptControl Method (scriptControl)
RegisterScriptDescriptors Method
RegisterScriptDescriptors Method (extenderControl)
RegisterScriptDescriptors Method (scriptControl)
RegisterStartupScript Method
RegisterStartupScript Method (control, type, key, script, addScriptTags)
RegisterStartupScript Method (page, type, key, script, addScriptTags)
Render Method (writer)
ResolveScriptReference Event
ScriptMode Property
ScriptPath Property
Scripts Property
Services Property
SetFocus Method
SetFocus Method (clientID)
SetFocus Method (control)
SupportsPartialRendering Property
Visible Property

ScriptManager Class

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

Syntax

CSharp

[ParseChildrenAttribute(true)]
[DefaultPropertyAttribute("Scripts")]
[DesignerAttribute("System.Web.UI.Design.ScriptManagerDesigner, System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
[NonVisualControlAttribute]
[PersistChildrenAttribute(false)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class ScriptManager : Control, IPostBackDataHandler

VisualBasic

<ParseChildrenAttribute(True)> _
<DefaultPropertyAttribute("Scripts")> _
<DesignerAttribute("System.Web.UI.Design.ScriptManagerDesigner, System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")> _
<NonVisualControlAttribute> _
<PersistChildrenAttribute(False)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class ScriptManager _
	Inherits Control _
	Implements IPostBackDataHandler

ManagedCPlusPlus

[ParseChildrenAttribute(true)]
[DefaultPropertyAttribute(L"Scripts")]
[DesignerAttribute(L"System.Web.UI.Design.ScriptManagerDesigner, System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
[NonVisualControlAttribute]
[PersistChildrenAttribute(false)]
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class ScriptManager : public Control, IPostBackDataHandler

JSharp

/** @attribute ParseChildrenAttribute(true) */
/** @attribute DefaultPropertyAttribute("Scripts") */
/** @attribute DesignerAttribute("System.Web.UI.Design.ScriptManagerDesigner, System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35") */
/** @attribute NonVisualControlAttribute */
/** @attribute PersistChildrenAttribute(false) */
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal) */
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal) */
public class ScriptManager extends Control implements IPostBackDataHandler

Members

IconMemberDescription
ScriptManagerNew()Initializes a new instance of the ScriptManager class.
AdapterGets the browser-specific adapter for the control. (Inherited from Control.)
AddedControl(Control, Int32)Called after a child control is added to the Controls collection of the Control object. (Inherited from Control.)
AddParsedSubObject(Object)Notifies 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.)
AllowCustomErrorsRedirectGets or sets a Boolean value that determines whether the custom errors section of the Web.config file is used during an error in an asynchronous postback.
ApplyStyleSheetSkin(Page)Applies the style properties defined in the page style sheet to the control. (Inherited from Control.)
AppRelativeTemplateSourceDirectoryGets or sets the application-relative virtual directory of the Page or UserControl object that contains this control. (Inherited from Control.)
AsyncPostBackErrorOccurs when there is a page error during an asynchronous postback.
AsyncPostBackErrorMessageGets or sets the error message that is sent to the client when an unhandled server exception occurs during an asynchronous postback.
AsyncPostBackSourceElementIDGets the unique ID of the control that caused the asynchronous postback.
AsyncPostBackTimeoutGets or sets a value that indicates the period of time, in seconds, before asynchronous postbacks time out if no response is received.
AuthenticationServiceGets the AuthenticationServiceManager object that is associated with the current ScriptManager instance.
BindingContainerGets the control that contains this control's data binding. (Inherited from Control.)
BuildProfileTree(String, Boolean)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.)
ChildControlsCreatedGets a value that indicates whether the server control's child controls have been created. (Inherited from Control.)
ClearChildControlState()Deletes the control-state information for the server control's child controls. (Inherited from Control.)
ClearChildState()Deletes the view-state and control-state information for all the server control's child controls. (Inherited from Control.)
ClearChildViewState()Deletes the view-state information for all the server control's child controls. (Inherited from Control.)
ClientIDGets the server control identifier generated by ASP.NET. (Inherited from Control.)
ClientIDSeparatorGets a character value representing the separator character used in the ClientID property. (Inherited from Control.)
ContextGets the HttpContext object associated with the server control for the current Web request. (Inherited from Control.)
ControlsGets a ControlCollection object that represents the child controls for a specified server control in the UI hierarchy. (Inherited from Control.)
CreateChildControls()Called 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.)
CreateControlCollection()Creates a new ControlCollection object to hold the child controls (both literal and server) of the server control. (Inherited from Control.)
DataBind()Binds a data source to the invoked server control and all its child controls. (Inherited from Control.)
DataBind(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.)
DataBindChildren()Binds a data source to the server control's child controls. (Inherited from Control.)
DataBindingOccurs when the server control binds to a data source. (Inherited from Control.)
DesignModeGets a value indicating whether a control is being used on a design surface. (Inherited from Control.)
Dispose()Enables a server control to perform final clean up before it is released from memory. (Inherited from Control.)
DisposedOccurs 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.)
EnablePageMethodsGets or sets a value that indicates whether static page methods on an ASP.NET page can be called from client script.
EnablePartialRenderingGets 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.
EnableScriptGlobalizationGets or sets a value that indicates whether the ScriptManager control renders script in the browser to support parsing and formatting culture-specific information.
EnableScriptLocalizationGets or sets a value that indicates indicating whether the ScriptManager control loads localized versions of script files.
EnableThemingGets or sets a value indicating whether themes apply to this control. (Inherited from Control.)
EnableViewStateGets 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.)
EnsureChildControls()Determines whether the server control contains child controls. If it does not, it creates child controls. (Inherited from Control.)
EnsureID()Creates an identifier for controls that do not have an identifier assigned. (Inherited from Control.)
Equals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
EventsGets a list of event handler delegates for the control. This property is read-only. (Inherited from Control.)
Finalize()Allows an Object to attempt to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
FindControl(String)Searches the current naming container for a server control with the specified id parameter. (Inherited from Control.)
FindControl(String, Int32)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 method. (Inherited from Control.)
Focus()Sets input focus to a control. (Inherited from Control.)
static memberGetCurrent(Page)Gets the ScriptManager instance for a given Page object.
GetDesignModeState()Gets design-time data for a control. (Inherited from Control.)
GetHashCode()Serves as a hash function for a particular type. (Inherited from Object.)
GetType()Gets the Type of the current instance. (Inherited from Object.)
HasChildViewStateGets a value indicating whether the current server control's child controls have any saved view-state settings. (Inherited from Control.)
HasControls()Determines if the server control contains any child controls. (Inherited from Control.)
HasEvents()Returns a value indicating whether events are registered for the control or any child controls. (Inherited from Control.)
IDGets or sets the programmatic identifier assigned to the server control. (Inherited from Control.)
IdSeparatorGets the character used to separate control identifiers. (Inherited from Control.)
InitOccurs when the server control is initialized, which is the first step in its lifecycle. (Inherited from Control.)
IsChildControlStateClearedGets a value indicating whether controls contained within this control have control state. (Inherited from Control.)
IsDebuggingEnabledGets a value that indicates whether the debug versions of client script libraries will be rendered.
IsInAsyncPostBackGets a value that indicates whether the current postback is being executed in partial-rendering mode.
IsLiteralContent()Determines if the server control holds only literal content. (Inherited from Control.)
IsTrackingViewStateGets a value that indicates whether the server control is saving changes to its view state. (Inherited from Control.)
IsViewStateEnabledGets a value indicating whether view state is enabled for this control. (Inherited from Control.)
LoadOccurs when the server control is loaded into the Page object. (Inherited from Control.)
LoadControlState(Object)Restores control-state information from a previous page request that was saved by the SaveControlState() method. (Inherited from Control.)
LoadPostData(String, NameValueCollection)Reads form data that is posted from the browser to the server and determines the source of the asynchronous postback.
LoadScriptsBeforeUIGets or sets a value that indicates whether scripts are loaded before or after markup for the page UI is loaded.
LoadViewState(Object)Restores view-state information from a previous page request that was saved by the SaveViewState() method. (Inherited from Control.)
LoadViewStateByIDGets a value indicating whether the control participates in loading its view state by ID instead of index. (Inherited from Control.)
MapPathSecure(String)Retrieves the physical path that a virtual path, either absolute or relative, maps to. (Inherited from Control.)
MemberwiseClone()Creates a shallow copy of the current Object. (Inherited from Object.)
NamingContainerGets a reference to the server control's naming container, which creates a unique namespace for differentiating between server controls with the same ID property value. (Inherited from Control.)
OnAsyncPostBackError(AsyncPostBackErrorEventArgs)Raises the AsyncPostBackError event.
OnBubbleEvent(Object, EventArgs)Determines whether the event for the server control is passed up the page's UI server control hierarchy. (Inherited from Control.)
OnDataBinding(EventArgs)Raises the DataBinding event. (Inherited from Control.)
OnInit(EventArgs)Raises the Init event and makes sure that only one ScriptManager control exists on the page. (Overrides Control.OnInit(EventArgs).)
OnLoad(EventArgs)Raises the Load event. (Inherited from Control.)
OnPreRender(EventArgs)Raises the PreRender event, and registers script blocks and services for partial-page updates. (Overrides Control.OnPreRender(EventArgs).)
OnResolveScriptReference(ScriptReferenceEventArgs)Raises the ResolveScriptReference event for each script reference that is managed by the ScriptManager control
OnUnload(EventArgs)Raises the Unload event. (Inherited from Control.)
OpenFile(String)Gets a Stream used to read a file. (Inherited from Control.)
PageGets a reference to the Page instance that contains the server control. (Inherited from Control.)
ParentGets a reference to the server control's parent control in the page control hierarchy. (Inherited from Control.)
PreRenderOccurs after the Control object is loaded but prior to rendering. (Inherited from Control.)
ProfileServiceGets the ProfileServiceManager object that is associated with the current ScriptManager instance.
RaiseBubbleEvent(Object, EventArgs)Assigns any sources of the event and its information to the control's parent. (Inherited from Control.)
RaisePostDataChangedEvent()Raises events for the ScriptManager control when it posts back to the server.
static memberRegisterArrayDeclaration(Page, String, String)Registers an ECMAScript (JavaScript) array declaration with the ScriptManager control each time an asynchronous postback occurs, and then adds the array to the page by using an array name and array value.
static memberRegisterArrayDeclaration(Control, String, String)Registers an ECMAScript (JavaScript) array declaration for a control inside an UpdatePanel control with the ScriptManager control, and adds the array to the page by using an array name and array value.
RegisterAsyncPostBackControl(Control)Registers a control for asynchronous postbacks, which can be used to update specific regions of the page .
static memberRegisterClientScriptBlock(Page, Type, String, String, Boolean)Registers a client script block with the ScriptManager control each time an asynchronous postback occurs, and then adds the script block to the page.
static memberRegisterClientScriptBlock(Control, Type, String, String, Boolean)Registers a client script block for a control inside an UpdatePanel control with the ScriptManager control, and then adds the script block to the page.
static memberRegisterClientScriptInclude(Page, Type, String, String)Registers client script with the ScriptManager control each time a postback occurs, and then adds a script file reference to the page.
static memberRegisterClientScriptInclude(Control, Type, String, String)Registers a client script file for a control inside an UpdatePanel control with the ScriptManager control, and then adds a script file reference to the page.
static memberRegisterClientScriptResource(Page, Type, String)Registers a client script file that is embedded in an assembly with the ScriptManager control each time a postback occurs.
static memberRegisterClientScriptResource(Control, Type, String)Registers the client script that is embedded in an assembly for a control inside an UpdatePanel control with the ScriptManager control.
RegisterDataItem(Control, String)Sends custom data that is represented by a string to a control during partial-page rendering.
RegisterDataItem(Control, String, Boolean)Sends custom data that is represented by a string to a control during partial-page rendering, and indicates whether the string is in JavaScript Object Notation (JSON) format.
RegisterDispose(Control, String)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. This method is used for client components that are part of the Microsoft AJAX Library and need to free resources when a component is no longer used.
static memberRegisterExpandoAttribute(Control, String, String, String, Boolean)Registers a name/value pair with the ScriptManager control as a custom (expando) attribute of a specified control.
RegisterExtenderControl<(Of TExtenderControl>)(TExtenderControl, Control)Registers an extender control with the current ScriptManager instance.
static memberRegisterHiddenField(Page, String, String)Registers a hidden field for every asynchronous postback by using the ScriptManager control.
static memberRegisterHiddenField(Control, String, String)Registers a hidden field for a control that is inside an UpdatePanel control by using the ScriptManager control.
static memberRegisterOnSubmitStatement(Page, Type, String, String)Registers ECMAScript (JavaScript) code for every asynchronous postback when the form is submitted.
static memberRegisterOnSubmitStatement(Control, Type, String, String)Registers ECMAScript (JavaScript) code for a control that is inside an UpdatePanel control that is executed when the form is submitted.
RegisterPostBackControl(Control)Registers a control for postback. This method is used for postback controls inside an UpdatePanel control that would otherwise perform asynchronous postbacks.
RegisterScriptControl<(Of TScriptControl>)(TScriptControl)Registers a script control with the current ScriptManager instance.
RegisterScriptDescriptors(IExtenderControl)Calls back to an ExtenderControl class to return instance scripts that must be rendered to support the client object.
RegisterScriptDescriptors(IScriptControl)Calls back to a ScriptControl class to return instance scripts that must be rendered to support the client object.
static 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.
static 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.
RemovedControl(Control)Called after a child control is removed from the Controls collection of the Control object. (Inherited from Control.)
Render(HtmlTextWriter)Renders the ScriptManager control's content to the browser by using the specified HtmlTextWriter object. (Overrides Control.Render(HtmlTextWriter).)
RenderChildren(HtmlTextWriter)Outputs 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.)
RenderControl(HtmlTextWriter)Outputs server control content to a provided HtmlTextWriter object and stores tracing information about the control if tracing is enabled. (Inherited from Control.)
RenderControl(HtmlTextWriter, ControlAdapter)Outputs server control content to a provided HtmlTextWriter object using a provided ControlAdapter object. (Inherited from Control.)
ResolveAdapter()Gets the control adapter responsible for rendering the specified control. (Inherited from Control.)
ResolveClientUrl(String)Gets a URL that can be used by the browser. (Inherited from Control.)
ResolveScriptReferenceOccurs when a member of the Scripts collection is registered with the ScriptManager control.
ResolveUrl(String)Converts a URL into one that is usable on the requesting client. (Inherited from Control.)
SaveControlState()Saves any server control state changes that have occurred since the time the page was posted back to the server. (Inherited from Control.)
SaveViewState()Saves any server control view-state changes that have occurred since the time the page was posted back to the server. (Inherited from Control.)
ScriptModeGets or sets a value that determines whether to render debug or release versions of client script libraries.
ScriptPathGets or sets the root path to the location that is used to build the paths to Microsoft ASP.NET 2.0 AJAX Extensions and custom script files.
ScriptsGets a ScriptReferenceCollection object that contains ScriptReference objects that are registered with the ScriptManager control declaratively or programmatically.
ServicesGets a ServiceReferenceCollection object that contains a ServiceReference object for each Web service that Microsoft ASP.NET 2.0 AJAX Extensions expose on the client.
SetDesignModeState(IDictionary)Sets design-time data for a control. (Inherited from Control.)
SetFocus(Control)Sets the browser focus to the specified control.
SetFocus(String)Sets the browser focus to the control that has the specified identifier.
SetRenderMethodDelegate(RenderMethod)Assigns an event handler delegate to render the server control and its content into its parent control. (Inherited from Control.)
SiteGets information about the container that hosts the current control when rendered on a design surface. (Inherited from Control.)
SkinIDGets or sets the skin to apply to the control. (Inherited from Control.)
SupportsPartialRenderingGets a value that indicates whether the client supports partial-page rendering.
TemplateControlGets or sets a reference to the template that contains this control. (Inherited from Control.)
TemplateSourceDirectoryGets the virtual directory of the Page or UserControl that contains the current server control. (Inherited from Control.)
ToString()Returns a String that represents the current Object. (Inherited from Object.)
TrackViewState()Causes 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 ViewState property. (Inherited from Control.)
UniqueIDGets the unique, hierarchically qualified identifier for the server control. (Inherited from Control.)
UnloadOccurs when the server control is unloaded from memory. (Inherited from Control.)
ViewStateGets 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.)
ViewStateIgnoresCaseGets a value that indicates whether the StateBag object is case-insensitive. (Inherited from Control.)
VisibleOverrides the Visible property that is inherited from the base Control class to prevent setting this value. (Overrides Control.Visible.)

Remarks

The ScriptManager control is central to Microsoft ASP.NET 2.0 AJAX Extensions. 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. Any script that you register is loaded after the Microsoft AJAX Library script to manage dependencies between your script and the core library.

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

  • Access Web service methods from script by registering Web services with the ScriptManager control.

  • Access ASP.NET authentication and profile application services from client script by registering these services with the ScriptManager control.

  • Display culture-specific information for the 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 renders only the regions of the page that need 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.

UpdatePanel controls require a ScriptManager control on the same page as the panel or on a parent page, such as a master page. However, a nested page can contain only one ScriptManager control in its hierarchy. To register services and scripts for nested pages or components when the parent page already has a ScriptManager control, use the ScriptManagerProxy control. For more information, see Using the UpdatePanel Control with Master Pages

Script Management and Registration Overview

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:

  • Methods for registering script files that guarantee that script dependencies on the Microsoft AJAX Library are maintained.

  • Methods for registering script files that are not dependent on the Microsoft AJAX Library but are compatible with UpdatePanel controls.

  • Methods that support working with UpdatePanel controls.

For more information about creating and using script in ASP.NET 2.0 AJAX Extensions, see Creating Custom Client Script in ASP.NET AJAX.

Registering Script That Is Dependent on the Microsoft AJAX Library

The following methods register script files in a way that guarantees that any dependencies on the Microsoft AJAX Library are maintained. 

RegisterScriptControl<(Of TScriptControl>)(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<(Of TExtenderControl>)(TExtenderControl, Control)

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

The following methods can be used 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.

RegisterArrayDeclaration

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

RegisterClientScriptBlock

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

RegisterClientScriptInclude

Renders a script block after the page's opening <form> element 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> element tag. The script content is specified with a resource name in an assembly. The src attribute is then automatically populated with a URL by using the HTTP handler that retrieves the named script from the assembly.

RegisterExpandoAttribute(Control, String, String, String, Boolean)

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 literal.

RegisterStartupScript

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

When you call these methods, if a script block, a script file, an onsubmit script, or a startup 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> tag 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

The following methods enable you to customize partial-page updates when you use UpdatePanel controls.

RegisterAsyncPostBackControl(Control)

Registers a control for asynchronous postbacks, which is a control that triggers a region of the page to refresh without a full-page update.

RegisterDataItem

Sends custom data to controls during partial-page rendering.

RegisterDispose(Control, String)

Registers a dispose script for a control 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 need to free resources when a component is no longer used.

RegisterPostBackControl(Control)

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

Web Service References

The Services collection of the ScriptManager control contains a ServiceReference object for each Web service that is registered with the ScriptManager control. ASP.NET AJAX generates a client proxy object for each ServiceReference object in the Services collection. You can add ServiceReference objects to the Services collection to register Web services at run time.

For more information about accessing Web services in script, see Exposing Web Services to Client Script and Calling Web Services from Client Script.

Localization

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:

  • For script files that are embedded in an assembly, the ScriptManager control uses the culture-specific assembly NeutralResourcesLanguageAttribute attribute, the resources packaged with the assembly, and the UI culture of the browser (if any) to determine the appropriate culture-specific or fallback culture-neutral script file to send to the browser.

  • For stand-alone script files, the ScriptManager control uses the ResourceUICultures property of the ScriptReference control to define the list of UI cultures that are supported.

  • When in debug mode, the ScriptManager control attempts to render a culture-specific script file that contains debug information. For example, if the ScriptManager control 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

  • 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.

For more information about localizing resources, see Localizing Resources for Component Libraries Overview.

Error Handling

The AsyncPostBackError event is raised when a page error occurs during asynchronous postbacks. 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 UpdatePanel Controls.

Examples

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.

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 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 element, the section determines how errors are displayed for the page. For more information, see customErrors Element (ASP.NET Settings Schema).

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.

Permissions

  • AspNetHostingPermission

    for operating in a hosted environment. Demand value: LinkDemand. Permission value: Minimal.

  • AspNetHostingPermission

    for operating in a hosted environment. Demand value: InheritanceDemand. Permission value: Minimal.

Inheritance Hierarchy

Object

Assembly: System.Web.Extensions (Module: System.Web.Extensions)