共用方式為


Sys.Application Class

Provides a run-time object that exposes client events and manages client components that are registered with the application. The members of this object are available globally after the client application has been initialized. The members can be invoked without creating an instance of the class.

Namespace: Sys

Inherits: Sys.Component, Sys.IContainer

Sys.Application.addComponent(componentVar);

Constructors

Name

Description

Sys.Application Constructor

Initializes a new instance of the Sys.Application class.

Members

Name

Description

Sys.Application.init Event

Raised after all scripts have been loaded but before objects are created.

Sys.Application.load Event

Raised after all scripts have been loaded and after the objects in the application have been created and initialized.

Sys.Application.navigate Event

Occurs when the user clicks the browser's Back or Forward button.

Sys.Application.unload Event

Raised before all objects in the client application are disposed.

Sys.Application.addComponent Method

Registers a component with the application and initializes it if the component is not already initialized.

Sys.Application.addHistoryPoint Method

Creates a history point and adds it to the browser's history stack.

Sys.Application.beginCreateComponents Method

Instructs the application to start creating components.

Sys.Application.beginUpdate Method

Called by the Sys.Application.beginUpdate Method to indicate that the process of setting component properties of the application has begun.

Sys.Application.dispose Method

Releases resources and dependencies held by the client application.

Sys.Application.disposeElement Method

Releases resources and dependencies associated with an element and its child nodes.

Sys.Application.endCreateComponents Method

Instructs the application to finish component creation.

Sys.Application.endUpdate Method

Called by the Sys.Application.endCreateComponents Method to indicate that the process of updating the application has completed.

Sys.Application.findComponent Method

Returns the specified Sys.Component object.

Sys.Application $find Method

Provides a shortcut to the findComponent method.

Sys.Application.getComponents Method

Returns an array of all components that have been registered with the application through the addComponent method.

Sys.Application.initialize Method

Initializes the application and raises the load event.

Sys.Application.notifyScriptLoaded Method

Called by a referenced script to indicate that the script has been loaded.

Sys.Application.raiseLoad Method

Raises the load event.

Sys.Application.raisePropertyChanged Method

Raises the Sys.INotifyPropertyChange.propertyChanged Event.

Sys.Application.registerDisposableObject Method

Registers an object that will require disposing with the application.

Sys.Application.removeComponent Method

Removes the object from the application and disposes the object if it is disposable.

Sys.Application.unregisterDisposableObject Method

Unregisters a disposable object from the application.

Sys.Application.updated Method

Called by the Sys.Application.endUpdate Method as a placeholder for additional logic.

Sys.Application.enableHistory Property

Gets or sets a value that indicates whether the Web application supports history point management.

Sys.Application.isCreatingComponents Property

Gets a value that indicates whether the application is in the process of creating components.

Sys.Application.isDisposing Property

Gets a value that indicates whether the application is in the process of disposing its resources.

Remarks

The Application object provides functions and events that support client-component development. The Application object is a single instance of the private Sys._Application class. The Application object is created when an ASP.NET AJAX page is viewed in the browser and persists for the life of the page. The Application object is responsible for raising client page life-cycle events such as pageInit, pageLoad, and pageUnload, and for managing the disposal of registered components.

Events

The Application object provides the init, load, and unload events, and it inherits the disposing and propertyChanged events from the base Component class. All of these events apply to the life cycle of the client application in the browser.

If partial-page rendering is supported and the page contains an UpdatePanel control, the PageRequestManager class provides additional events that apply to the parts of the page that are rendered asynchronously. For more information about partial-page rendering, see Partial-Page Rendering Overview.

Individual components can expose events that apply only to the component. They can also access application-level events by using the Application object.

In most cases, page developers should put their code in the load event. At that point in the page life cycle, all scripts are loaded and all components have been created and ready to use. Any code that is included in a function named pageLoad will automatically run when the page loads.

Component developers can access other events or bind additional handlers to the load or unload events by invoking the event's add_ accessor method and passing the handler function. The following example shows how to bind a function named myUnloadHandler to the unload event.

Sys.Application.add_unload(myUnloadHandler)

When an event and its handlers are no longer needed, you can call the remove_ accessor method, as in the following example:

Sys.Application.remove_unload(myUnloadHandler);

You can attach additional handlers to an event by calling the add_ accessor one time for each handler. Handlers are removed individually by calling the remove_ accessor method.

For more information about the Sys.Application events, see Ajax Client Life-Cycle Events.

Adding Components

In most scenarios, you should add components to an application by using the $create command. After a component has been registered with the application, you can access it in the application by calling the findComponent method or the $find shortcut. You can get a list of all available components by calling the getComponents method.

For more information about how to develop components, controls, and behavior, see Adding Ajax Functionality to ASP.NET Controls.

Referencing Script Files

If you reference a stand-alone script file (.js file) for use with partial-page rendering, the code in the script file can call the notifyScriptLoaded method, however it is no longer required. This method notifies the application that the script has finished loading. For more information, see Sys.Application.notifyScriptLoaded Method.

See Also

Other Resources

Language Reference