Skip to main content
All docs
V23.2

Cannot unregister UpdatePanel with ID since it was not registered with the ScriptManager

  • 3 minutes to read

Error Description

If you place ASP.NET AJAX UpdatePanel into a DevExpress container (such as ASPxSplitter, ASPxPopupControl, or ASPxPageControl), you can get the following exception during a container callback:

Cannot unregister UpdatePanel with ID {id} since it was not registered with the ScriptManager. This might occur if the UpdatePanel was removed from the control tree and later added again, which is not supported.

Explanation

The UpdatePanel is automatically registered in the ScriptManager in the panel’s Init event handler. Note that a panel is registered only once with the same identifier during a page life cycle. In the Unload event, the UpdatePanel is unregistered.

The issue occurs if the UpdatePanel is created dynamically or placed in a container whose child control hierarchy can be changed during the page life cycle. When the child control hierarchy is cleared and recreated, an old UpdatePanel clears its registration, but a new UpdatePanel with the same identifier is not registered again. An attempt to unregister the panel in the Unload event causes an exception.

Solutions

You can use the following techniques to solve the issue:

Replace UpdatePanel with ASPxCallbackPanel

You can replace an UpdatePanel with an ASPxCallbackPanel. Moreover, many DevExpress containers, such as an ASPxPopupControl or ASPxPageControl, have a built-in callback panel, so you do not need to add an UpdatePanel nor ASPxCallbackPanel to refresh their content.

Disable Dynamic Change of Hierarchy

Try the following recommendations that can be effective in certain scenarios:

  • If a container control does not change its structure, disable the control’s EnableHierarchyRecreation property.
    Note that this solution can cause issues with a control hierarchy if you change it on callbacks. Please refer to the EnableHierarchyRecreation property description for details.
  • Do not rebind a container and do not call the FindControl method in the page or control Init event.
  • Place the UpdatePanel into a UserControl and append it to a container hierarchy in the page Load event.

Register UpdatePanel Before Unload

Important

This solution uses classes of the System.Reflection namespace that do not operate in Medium .NET Trust Level.

To solve the issue, register the UpdatePanel in the ScriptManager between two unregistered events.

  1. Handle the UpdatePanel.Unload event.

    <asp:UpdatePanel ID="UpdatePanel1" runat="server" OnUnload="UpdatePanel1_Unload">  
    
  2. In the event handler, register the UpdatePanel in the ScriptManager before the panel is unloaded.

    protected void UpdatePanel_Unload(object sender, EventArgs e) {  
        MethodInfo mInfo = typeof(ScriptManager).GetMethod(
            "System.Web.UI.IScriptManagerInternal.RegisterUpdatePanel", 
            BindingFlags.NonPublic | BindingFlags.Instance);  
        if(mInfo != null)  
            mInfo.Invoke(ScriptManager.GetCurrent(Page), new object[] { sender as UpdatePane });  
    }