是否可以在onet.xml中分配webpart id?

时间:2009-08-28 06:33:13

标签: c# .net sharepoint wss

我制作了一个有三个区域的页面。在onet.xml中,我定义了三个webpart,它们将在创建网站时添加到页面中。是否可以为onet.xml中的每个webpart分配一个id,或者我是否需要编写一个连接连接的功能接收器?

我最初的想法是在页面上使用,但后来我需要webparts的id。

2 个答案:

答案 0 :(得分:0)

<AllUsersWebPart WebPartZoneID="TopColumnZone" WebPartOrder="1"><![CDATA[
            <webParts>
                <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
                    <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>

如果您查看上面的代码段,所有属性都在“属性”标签中定义,您是否尝试过向其添加ID,我猜它应该有用。

<property name="ID" type="string">WebPart1</property>

答案 1 :(得分:0)

我找到了两个解决方案。一种是将webpart添加到页面布局,但不添加到区域中。那么你可以使用id来连接它们。

但我采用的解决方案是在我的一个webparts中创建一个“InitConnection”函数,它在第一次运行时连接页面上的所有其他webpart。

我认为可以对功能装订做同样的事情,但我所采用的解决方案很简单且代码很少。