views:

372

answers:

2

I've made a page with with three zones. In onet.xml I have defined three webparts which will be added to the page upon site creation. Is it possible to assign an id to each webpart in onet.xml, or do I need to write a feature receiver which hooks up the connections?

My initial thought was to use on the page itself, but then I need the id's of the webparts.

A: 
<AllUsersWebPart WebPartZoneID="TopColumnZone" WebPartOrder="1"><![CDATA[
            <webParts>
                <webPart xmlns="http://schemas.microsoft.com/WebPart/v3"&gt;
                    <metaData>
                        <type name="Microsoft.SharePoint.Publishing.WebControls.TableOfContentsWebPart,Microsoft.SharePoint.Publishing,Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" />
                        <importErrorMessage>$Resources:cmscore,WebPartImportError;</importErrorMessage>
                    </metaData>
                    <data>
                        <properties>
                            <property name="Title" type="string">$Resources:cmscore,PublishingLayouts_TOCWebPart_Title;</property>
                            <property name="Description" type="string">$Resources:cmscore,PublishingLayouts_TOCWebPart_Description;</property>
                            <property name="ShowPages" type="bool">True</property>
                            <property name="IncludeContentFromStartingLocation" type="bool">False</property>
                            <property name="ChromeType" type="chrometype">None</property>
                            <property name="ChromeState" type="chromestate">Normal</property>
                            <property name="HelpUrl" type="string">/_layouts/help.aspx</property>
                        </properties>
                    </data>
                </webPart>
            </webParts>]]>
        </AllUsersWebPart>

If you look at the above snippet all the Property are defined in the Properties tag, have you tried to add a ID to it , My guess is it should work.

<property name="ID" type="string">WebPart1</property>
Kusek
It replaces the ID I put in onet.xml with a g_{random guid} on site creation. I guess I have to go the programmatic way or just hook it up in the GUI manually.
Mikael Svenson
A: 

I've found two solutions. One is to add the webparts to a page layout, but not in zones. then you can use the id's to hook them up.

But the solution I went for was to create a "InitConnection" function in one of my webparts which hooks up all the other webparts on the page the first time it's run.

I think it would be possible to do the same with feature stapling, but the solution I went for was easy and little code.

Mikael Svenson