Does anyone know of an example that demonstrate how to use the SPWebPartConnection to connect two web parts on a standard page?
All I'm trying to do is have two different web parts exchange a single string value. I'm getting a bit confused between WebPartConnection and SPWebPartConnection. My code is below which I've been fiddling but so far haven't managed to get a breakpoint in the provider web part SetConnection method to fire. I'm assuming that it's the first thing that has to work.
On my aspx page I have (unrelated attributes removed for brevity):
<WebPartPages:spproxywebpartmanager runat="server" id="spproxywebpartmanager">
<SPWebPartConnections>
<WebPartPages:SPWebPartConnection
id="connection1"
ProviderID="viewer"
ConsumerID="details"
ConsumerConnectionPointID="consumer"
ProviderConnectionPointID="provider"/>
</SPWebPartConnections>
</WebPartPages:spproxywebpartmanager>
<WebPartPages:WebPartZone runat="server" ID="TopColumnZone">
<ZoneTemplate>
<WpNs0:MyViewer runat="server" ID="viewer" ...">
</WpNs0:MyViewer>
</ZoneTemplate>
</WebPartPages:WebPartZone>
<WebPartPages:WebPartZone id="g_0029D1EFB02B409DBDF4EFDB8E0560B8" runat="server">
<ZoneTemplate>
<WpNs0:MyDetails runat="server" ID="details" ...>
</WpNs0:ClassifiedDetails>
</ZoneTemplate>
</WebPartPages:WebPartZone>
Provider web part class:
public class ClassifiedsViewer : WebPart, System.Web.UI.WebControls.WebParts.IWebPartField
{
...
public void GetFieldValue(System.Web.UI.WebControls.WebParts.FieldCallback callback)
{
callback("some string");
}
[System.Web.UI.WebControls.WebParts.ConnectionProvider("FieldProvider", "provider")]
public IFilterValues SetConnection(System.Web.UI.WebControls.WebParts.IWebPartField provider)
{
return this;
}
}
Consumer web part class:
public class ClassifiedDetails : WebPart
{
protected strign myProperty;
...
private void GetFieldValu(object fieldValue)
{
myProperty = fieldValue as string;
}
[System.Web.UI.WebControls.WebParts.ConnectionConsumer("FieldConsumer", "consumer", typeof(SPWebPartConnection), AllowsMultipleConnections = true)]
public void SetConnectionInterface(System.Web.UI.WebControls.WebParts.IWebPartField provider)
{
m_provider = provider;
}
}