Adding default web parts programmatically on SharePoint 2010 Page Layouts

Shows a way of adding default web parts within page layouts at runtime during page editing using a server control. An alternative to using the <AllUsersWebPart> element.

 
 
 
 
 
4.7 Star
(6)
Add to favorites
4/20/2011
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • How to add it via SharePoint Designer
    1 Posts | Last post October 23, 2012
    • Hi Tobias,
      
      I've been searching how to add the webpart to the page layout with sharepoint designer but I can't seem to find it.
      
      Can you give me a guidance on that?
      
      Thanks.
  • How to register DefaultWebPartRegistration?
    2 Posts | Last post March 13, 2012
    • Hello, Tobias.
      
      How do I register the DefaultWebPartRegistration? I tried it with the ff. in my pagelayout:
      
      <%@ Register Tagprefix="wp" Namespace="SPProject.Controls"%>
      
      But after creating the page I get the ff. error:
      
      Unknown server tag 'wp:DefaultWebPartRegistration'.
      
      Regards,
      Gary
    • Hi Gary,
      
      I assume that the DefaultWebPartRegistration class is added to the SPProject.Controls namespace. In this case, you both need to add a SafeControl entry for the namespace and add the @Assembly instruction on the page.
      
      You can add the SafeControls entries using the Visual Studio GUI. For a guide, look at this post: http://msdn.microsoft.com/en-us/library/ee805045.aspx
      
      To add the assembly preprocessor, you can use the dynamic declaration of the SharePoint project using this syntax:
      
      <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
      
      This will add the assembly name according to your setup.
      
      Hope this helps!
  • The code works only when page is edited
    2 Posts | Last post September 26, 2011
    • Hi Tobias,
      
      This is a great post.  The only thing i would like to ask is.  The default web parts gets added to a page only when the page is edited.  They dont appear on the page immed. after creating the page using a page layout.  please could you help.
      
      Thanks,
      Deepak
    • Hi, what account is creating the page?
      
      The functionality is not meant for programmatic creation or for use with site definitions - in that case I provision the web parts using a module in the site def.
      
      Have you got any further information or steps that can guide me in helping you?