Saturday, October 22, 2011

ASP.NET AjaxControlToolkit Popup Extension not popping up

Today we had a problem with an popup extension. This was caused by storing the control in a session and use it for later. We have to make sure that Sessions are only used to store data, not full ASP.NET controls. So when you see something like the followin in your code:
Session["Popup"] = popupControl;
popupControl = Session["Popup"];
There is a chance that after a postback from the client, the popup is unable to show. The solution was to recursively find the popup control by looking in all parent controls:
private T FindParentControl( T control )
    where T : class
    if( control.Parent is T )
        return control.Parent as T;
    return control.Parent != null ? FindParentControl( control.Parent ) : null;
This is also posted at stack overflow: