ScriptManager::RegisterDispose Method (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.

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

void RegisterDispose(
	Control^ control,
	String^ disposeScript


Type: System.Web.UI::Control^

The control that the dispose script is for.

Type: System::String^

The dispose script.

Exception Condition

control is null.

- or -

disposeScript is null.


control is not found on the page.

- or -

control is not inside an UpdatePanel control.

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 and events of the class.

.NET Framework
Available since 3.5
Return to top