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
Syntax
Sys.Application.addComponent(componentVar);
Members
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 ASP.NET 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 behaviors, see ASP.NET AJAX Extensibility.
Referencing Script Files
If you reference a standalone script file (.js file) for use with partial-page rendering, the code in the script file must call the notifyScriptLoaded method. This notifies the application that the script has finished loading. For more information, see notifyScriptLoaded Method.