Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

A specific custom web part is being instantiated twice on a certain page layout, even if it’s only declared once on the page layout.

Declaration like this:

    <%@ Register tagprefix="MyQuickLinks" namespace="Client.Intranet.MyLinksWebPart.MyLinks" assembly="Client.Intranet.MyLinksWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxx" %>

    <WebPartPages:webpartzone runat="server" Title="Web Part Content" ID="WebPartContent">
        <ZoneTemplate>
            <MyQuickLinks:MyLinks ID="MyLinks" Title = "My quicklinks" runat="server"/>
        </ZoneTemplate>
        </WebPartPages:webpartzone>

Creating a new page based on page layout shows web part is rendered/displayed twice.

HTML getting rendered like this--

The first one always:

    <DIV id="WebPartctl00_m_MyLinks" class="ms-WPBody noindex ms-wpContentDivSpace" allowDelete="false" width="100%" HasPers="false" WebPartID="00000000-0000-0000-0000-000000000000" allowExport="false">

*web part ID being all zeroes is strange, cause unknown

The second one always:

    <DIV id="WebPartctl00_m_g_e825e9c9_f070_4ea3_8231_dfda8fbe90a6" class="ms-WPBody noindex ms-wpContentDivSpace" allowDelete="false" width="100%" HasPers="false" WebPartID="657a284d-7048-4713-b792-7a792fe507ad" allowExport="false">

On Edit mode, the first web part cannot be removed and does not show in ‘Open page in web part maintenance’ mode, as if it were not contained in a web part zone

The second one, can be removed like any normal web part

Can no longer add a new web part of the same type to the same page.

Other page layouts that have the exact same web part declaration do not see this issue, and web parts are instantiated only once, and are able to add the same type of web part to the same page several times without error

This is a new SP2010 built from clean/vanilla stand-alone VM.

Please help

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Webparts added to a pagelayout's aspx file are basically rendered as controls. So it can;t be edited or removed etc.

You need to add it using an AllUsersWebPart element in the feature you use to deploy the pagelayout.

share|improve this answer
    
Thanks, that makes sense. I've removed the ID= property of the MyQuickLinks:MyLinks tag (for concurrency issue acc. to williamvanstrien.blogspot.com/2010/01/…) and managed to get rid of the WebPartID="00000000-0000-0000-0000-000000000000"...but still 2 instances are showing up –  zee Jun 27 '11 at 2:19
    
I'm trying to deploy the web part using AllUsersWebPart now, but keep getting "Cannot recognize the XML namespace of this Web Part" error when opening the page layout after deployment. I got the CDATA from exporting the custom web part itself, so not sure what's wrong there.. –  zee Jun 27 '11 at 4:15
    
rolandoldengarm.wordpress.com/2011/03/02/… This fixed the 'XML namespace' issue. The whole thing works now--definitely must use AllUsersWebPart for instantiating web parts into page layouts. –  zee Jun 28 '11 at 3:12
    
That's my colleague, whahaha! –  Colin Jun 28 '11 at 9:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.