Adding ECQWP to a Layout Page

Aug 6, 2008 at 9:10 PM

Hi there,

I wanted to add the Enhanced Content Query Web Part to a few of my custom layout pages so it can be pre-configured to display certain things any time a page is created.  But when add the exported web part to the layout page in a ZoneTemplate block of a WebPartZone and try to create a page with the layout, I get an error that reads:


No parameterless constructor defined for this object.   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
   at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type) ...
  <trim>


Has anyone been able to successfully add this web part to a layout page?  If so, how did you do it?  If I can't get this working, then I'll be forced to have to manually add the WP to each of the pages, which is tedious and I would rather avoid.

Many thanks in advance,
-Dan

Oct 22, 2008 at 6:06 PM
Edited Oct 22, 2008 at 6:07 PM

When you are in SPD - and you have the ecqwp on the page - in design view - double click on it and the properties pane will come up. Then you can set the properties like you would - in the ui when adding it manually for each page.

then you can look at the code view - to see what that does, there are a few extra properties in the ecqwp that aren't there in the cqwp - they are the ones avaiable in the properties pane.

 

Oct 22, 2008 at 6:51 PM
Thank you for the reply, but I think you're describing how to configure the ecqwp...I was having a difficult time even getting it into a page layout.  When you're in a page layout (not in SPD, but as a feature or solution), you have the ability to add some default wep parts to zones so any pages that you create with them already have the web parts in them.  This is what I was trying to do with the ecqwp.

Since I first posted this question, I've come to realize that the class the wep part inherits from is the key to whether or not you get this error message.  There's two web part classes that you can inherit from, one is in the Office namespace, and the other is "Microsoft.SharePoint.WebPartPages.WebPart."  Web parts inheriting from one will work in layout pages, the other will not (I think the Microsoft.SharePoint namespace is the one that works...but it's been a while.) 

I discovered this while trying to add some of my custom web parts to the layouts pages.  If I changed the web part class they inherited from, they error went away and they started working.  So, if anyone else out there is trying to add web parts to your page layouts and you see the above error message, try changing the inheritance of your web part class to make it start working!!

But thank you for your post paisleygo!
-Dan