Using PageDataSource (was ParentDataSource) with ASP.NET Web Site projects

I got a request today from somebody who was trying to use my ParentDataSource (now called PageDataSource) control in an ASP.NET Web Site project and was running into problems. The bound control kept throwing an InvalidOperationException saying it couldn’t load the type. Turns out the problem is with the difference in the way that pages and assemblies are dynamically compiled and loaded by the BuildManager in web site projects. The fix involves simple adding the dynamic assembly name to the type name so that the BuildManager can locate it correctly when the bound control asks for it:

if (ctl.Parent == null)
    // At the top of the control tree and user control was not found, use page base type instead
    this.TypeName = Assembly.CreateQualifiedName(
    _parentHost = this.Page;

You can download the updated control class file from here.


%d bloggers like this: