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.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: