Bewerken

Share via


ScriptManager.RegisterDispose(Control, String) Method

Definition

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.

public:
 void RegisterDispose(System::Web::UI::Control ^ control, System::String ^ disposeScript);
public void RegisterDispose (System.Web.UI.Control control, string disposeScript);
member this.RegisterDispose : System.Web.UI.Control * string -> unit
Public Sub RegisterDispose (control As Control, disposeScript As String)

Parameters

control
Control

The control that the dispose script is for.

disposeScript
String

The dispose script.

Exceptions

control is null.

-or-

disposeScript is null.

control is not found on the page.

-or-

control is not inside an UpdatePanel control.

Remarks

Use the RegisterDispose method to register dispose scripts for controls that are inside an UpdatePanel control. During asynchronous postbacks, UpdatePanel controls can be updated, deleted, or created. When a panel is updated or deleted, any dispose scripts that are registered for controls that are inside the UpdatePanel are called. In typical page development scenarios, you do not have to call the RegisterDispose method.

The RegisterDispose method is intended for use by control developers to register script or create controls that inherit from the IScriptControl interface. For example, you might use a dispose script if you develop a client control by using composition. In your control, you implement IScriptControl and render individual controls. You register the dispose method of any item that does not correspond to a defined client component such as Sys.TextBox. If your custom control composes elements that correspond to client components in the Microsoft Ajax Library, you do not have to register a dispose script, because dispose is called automatically. Therefore, use the RegisterDispose method for client components that are part of the Microsoft Ajax Library and that have to free resources when a component is no longer used.

The RegisterDispose method can be called multiple times for a control. Multiple scripts are aggregated. The order of disposing scripts matches the order in which the scripts were registered.

If you register a dispose script for a control that is not in an UpdatePanel control, an exception is thrown. The dispose script is called between the pageLoading and pageLoaded events of the PageRequestManager class.

Applies to

See also