1
votes

I am new to sharepoint. I don't know if this is possible or not. I have two web parts, one has two values which I need to pass to the second web part. Is there any way doing that or I can only have one connection/ Thanks

I have two visual web parts. In Provider I have two dropdownlists which I need to pass the values to Consumer. Here is the code:

public interface IMyConnection { int AreaId { get; } int TopicId { get; } }

public class Provider : WebPart, IMyConnection
{
    private Control control;

    protected override void CreateChildControls()
    {
        control = Page.LoadControl(_ascxPath);
        Controls.Add(control);
        base.CreateChildControls();
    }

    public int AreaId
    {
        get { return 1; }
    }

    public int TopicId
    {
        get { return 2; }
    }

    [ConnectionProvider("TopicId", "TopicId", AllowsMultipleConnections = true)]
    public IMyConnection SetTopicConnection()
    {
        return this;
    }

    [ConnectionProvider("AreaId", "AreaId", AllowsMultipleConnections = true)]
    public IMyConnection SetAreaConnection()
    {
        return this;
    }
}

public class Consumer : WebPart
{
    private IMyConnection connection;
    private Control control;

    protected override void CreateChildControls()
    {
        control = Page.LoadControl(_ascxPath);
        Controls.Add(control);
    }

    [ConnectionConsumer("TopicId", "TopicId", AllowsMultipleConnections = true)]
    public void GetTopicConnection(IMyConnection theConnection)
    {
        connection = theConnection;
    }

    [ConnectionConsumer("AreaId", "AreaId", AllowsMultipleConnections = true)]
    public void GetAreaConnection(IMyConnection theConnection)
    {
        connection = theConnection;
    }

    protected override void RenderContents(HtmlTextWriter writer)
    {
        if (connection != null)
        {
            //do work
        }
        base.RenderContents(writer);
    }
}

When I try to set the connections, it doesn show both but only set the Topic connection.

2

2 Answers

1
votes

One solution might be to split up your interface into IAreaProvider and ITopicProvider. I think the two connections aren't showing up because you can't provide two connections for the same interface.

0
votes

It depends on how the web parts are designed. Most out of the box ones are only designed to have one. If you write your own webpart you can declare as many connection provider interfaces as you want/need.