1
我已經創建了多個需要連接的主/細節Web部件。我們要求Web部件自己發現並連接到頁面上的其他可連接Web部件。我在一個標準的ASP.NET頁面下面的代碼來達到的這樣:SharePoint/WSS3.0:在運行時創建靜態Web部件連接
protected override void OnLoad(EventArgs e)
{
WebPartManager manager = WebPartManager.GetCurrentWebPartManager(Page);
manager.StaticConnections.Add(new WebPartConnection()
{
ID = string.Format("WebPartConnection{0}{1}", this.ID, provider.ID),
ConsumerID = this.ID,
ConsumerConnectionPointID = "WebPartConnectableConsumer",
ProviderID = provider.ID,
ProviderConnectionPointID = "WebPartConnectableProvider"
});
}
這種方法,然而,這並不在SharePoint工作。在一個通用的SharePoint錯誤使用這些對象結果的SharePoint版本:
protected override void OnLoad(EventArgs e)
{
SPWebPartManager spManager = SPWebPartManager.GetCurrentWebPartManager(Page) as SPWebPartManager;
spManager.StaticConnections.Add(new WebPartConnection()
{
ID = string.Format("WebPartConnection{0}{1}", this.ID, provider.ID),
ConsumerID = this.ID,
ConsumerConnectionPointID = "WebPartConnectableConsumer",
ProviderID = provider.ID,
ProviderConnectionPointID = "WebPartConnectableProvider"
});
}
以下方法工作,但創建連接,用戶的個性化的一部分:
protected override void OnLoad(EventArgs e)
{
SPWebPartConnection connection = (from SPWebPartConnection c in spManager.SPWebPartConnections where c != null && c.Consumer == this && c.ConsumerConnectionPointID == "WebPartConnectableConsumer" && c.Provider == provider select c).FirstOrDefault();
if (connection == null)
{
try
{
ProviderConnectionPointCollection providerCollections = spManager.GetProviderConnectionPoints(provider);
ConsumerConnectionPointCollection consumerConnections = spManager.GetConsumerConnectionPoints(this);
connection = spManager.SPConnectWebParts(provider, providerCollections["WebPartConnectableProvider"], this, consumerConnections["WebPartConnectableConsumer"]);
}
catch { }
}
}
,您可以檢查的SharePoint日誌文件或事件查看器來查看是否有更詳細的錯誤信息,可以在故障排除問題幫助嗎? – 2010-05-24 18:59:07
感謝您的日誌建議。我對SharePoint開發稍微陌生,但仍然習慣於開發模式。我真的忘了打開詳細的日誌記錄。 – etc 2010-05-25 10:58:26