Hello,
I can't seem to find any information on how best to implement multiple connections on a consumer web part and was wondering if anyone could point me in the right direction.
I have three web parts: two containing grids of data (the providers) and one containing item detail (the consumer). All of the web parts implement a known interface to enable the connections, and the AllowsMultipleConnections attribute is set to 'true' on the consumer connection point. The desired behaviour is that when an item is selected in EITHER of the grids of data, the information is correctly retrieved and displayed in the connected item detail web part.
Both providers implement their connections (in C#) along the following lines:
[System.Web.UI.WebControls.WebParts.ConnectionProvider("Provides ML Object", "ProviderWebPartMLObjectProvider")]
public Controls.IMLObject IMLObjectProvider()
{
return this;
}
and the ConsumerWebPart consumer is something like:
[System.Web.UI.WebControls.WebParts.ConnectionConsumer("IMLObject Consumer","ConsumerWebPartMLObjectConsumer",AllowsMultipleConnections=true)]
public void IMLObjectConsumer(Controls.IMLObject MLObject)
{
if (MLObject != null)
{
SomeUniqueCode = MLObject.UniqueCode;
}
else
{
// throw some exception
}
}
I was originally connecting the web parts in the codebehind but have since moved the declarations into the WebPartManager as follows:
<asp:WebPartManager ID="WebPartManager" runat="server">
<StaticConnections>
<asp:WebPartConnection ID="ThisConnection" ConsumerID="ConsumerWebPart" ConsumerConnectionPointID="MLObjectConsumer" ProviderID="ProviderWebPart" ProviderConnectionPointID="ProviderWebPartEntityProvider"></asp:WebPartConnection>
</StaticConnections>
</asp:WebPartManager>
The setup above works fine for the single connection, but if I try to add another <asp:WebPartConnection> to connect the secondary provider with the same consumer, only the 'last' connection specified actually connects properly, populating the desired data. Strangely enough, analysing the execution order in the page's trace, I can see that the 'first' connection's provider is called, followed by TWO consumptions by the consumer, even though the data actually retrieved is from the 'last' provider in the StaticConnections list.
I hope the above makes sense, as typing out the problem long-hand doesn't really seem to to me! Any pointers?
Thanks,
Marc