Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I created a simple web part that has both a consumer and a provider connection. The provided output depends on the consumed input (so this is a sort of pipeline approach). I managed to implement the web part and set up both the connections on an SP page. However, the web part does not work in practice because Sharepoint actually calls the provider method before the data to consume has been received (this seems rather senseless to me). I discovered this using debug prints. (See the code on the bottom for more information.)

Now running SetConnectionInterfaceForOutput
Now running ParameterValues (output is "")
Now running SetConnectionInterfaceForInput
Now running getFieldValue (received input "1;#A")

So, the question is: is there any way to force Sharepoint call the consumer method before the provider method?

[ToolboxItemAttribute(false)]
public class LookupValueProcessorFilter : WebPart, Microsoft.SharePoint.WebPartPages.ITransformableFilterValues
{
    private string input = "";
    private string output = "";
    private string debugString = "";
    Label debugLabel;

    [ConnectionConsumer("Lookup value input", "IWebPartField", AllowsMultipleConnections = false)]
    public void SetConnectionInterfaceForInput(IWebPartField provider)
    {
        debugString += "Now running SetConnectionInterfaceForInput<br />";
        provider.GetFieldValue(new FieldCallback(getFieldValue));
    }

    private void getFieldValue(object fieldValue)
    {
        input = fieldValue.ToString();
        debugString += "Now running getFieldValue (received input \"" + input + "\")<br />";
    }

    [ConnectionProvider("Lookup value output", "ITransformableFilterValues", AllowsMultipleConnections = true)]
    public Microsoft.SharePoint.WebPartPages.ITransformableFilterValues SetConnectionInterfaceForOutput()
    {
        debugString += "Now running SetConnectionInterfaceForOutput<br />";
        return this;
    }

    public virtual System.Collections.ObjectModel.ReadOnlyCollection<string> ParameterValues
    {
        get
        {
            debugString += "Now running ParameterValues (output is \"" + output + "\")<br />";

            Microsoft.SharePoint.SPFieldLookupValue lookupValue = new Microsoft.SharePoint.SPFieldLookupValue(input);
            output = lookupValue.LookupValue;
            return new System.Collections.ObjectModel.ReadOnlyCollection<string>(new string[] { output });
        }
    }

    protected override void CreateChildControls()
    {
        base.CreateChildControls();

        debugLabel = new Label();
        this.Controls.Add(debugLabel);
    }

    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
        debugLabel.Text = debugString;
    }

    public virtual bool AllowMultipleValues
    {
        get {return true;}
    }

    public virtual bool AllowAllValue
    {
        get {return true;}
    }

    public virtual bool AllowEmptyValue
    {
        get {return false;}
    }

    public virtual string ParameterName
    {
        get {return "Lookup value";}
    }
}
share|improve this question

1 Answer 1

up vote 0 down vote accepted

Finally, I gave up passing information through a web part. In our case, the required input information is actually available in the current SPContext object. So, instead of having a consumer-provider web part, we have now a web part that provides information that is available in SPContext.

Another solution I tried was to implement both the consumer and the provider interface with IWebPartParameters. I never got it to function properly, but I suspect it might be possible with some more work.

In case anyone wants to try passing information through a web part with IWebPartParameters, here are the resources I used:

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.