开发者

Can a SharePoint WebPart connect to a custom SharePoint WebPart

I need to consume a value passed by the default sharepoint filter webpart. I don't see how a custom sharepoint webpart can establish a connect and get data. Is this even possible?

Updated

The provider WebPart is a default SharePoint List Filter WebPart. The consumer WebPart is a custom WebPart

This is the code I came up with, but the "connections" option is still greyed out on the SharePoint page. On the page, I have a SharePoint List Filter WebPart and my CustomPageViewer WebPart.

namespace PageViewerWithConnections.CustomPageViewer
{
    [ToolboxItemAttribute(false)]
    public class CustomPageViewer : System.Web.UI.WebControls.WebParts.WebPart
    {
        IFilterValues _filterVals;

        [ConnectionConsumer("Consumer connection", "Consumer param")]
        public void ConsumeFilter(IFilterValues filterValues)
        {
            _filterVals = filterValues;
        }

        Microsoft.SharePoint.开发者_如何学编程WebPartPages.PageViewerWebPart objPageViewer;
        protected override void CreateChildControls()
        {

        }
    }
}

Reason's for this approach My goal is to set a different URL to the page viewer Web Part based on the value I get from a SharePoint List Filter Web Part. It seems that the SharePoint List Filter WebPart cannot send data to a Page Viewer WebPart.


You'll need to create a consumer method on your custom webpart that takes an instance of IFilterValues as an argument and uses the ConnectionConsumerAttribute Attribute.

private IFilterValues _filterVals;

[ConnectionConsumer("Filter Consumer", "FilterConsumer")]
public void ConsumeFilter(IFilterValues filterValues)
{
    _filterVals = filterValues;
}

Note that the consumption of the filter values occurs during the OnPreRender stage of the page lifecycle, so you'll need to override the OnRender method to act on any values consumed from the connection, or include the logic in the consumer method.

For more information, check out these links:

http://msdn.microsoft.com/en-us/library/ms494838(v=office.12).aspx

http://msdn.microsoft.com/en-us/library/ms469765.aspx


In the CreateChildControls you should call base.CreateChildControls();

Here is some working code:


    List<IFilterValues> providers = new List<IFilterValues>();

protected override void CreateChildControls() { if (providers.Count > 0 && providers[0].ParameterValues != null) { this.FilterValue1 = providers[0].ParameterValues[0]; } base.CreateChildControls(); } [ConnectionConsumer("Provider WebPart", "IFilterValues", AllowsMultipleConnections = false)] public void SetConnectionInterface(IFilterValues provider) { if (provider != null) { this.providers.Add(provider); List<ConsumerParameter> parameters = new List<ConsumerParameter>(); parameters.Add(new ConsumerParameter("param1", ConsumerParameterCapabilities.SupportsSingleValue | ConsumerParameterCapabilities.SupportsEmptyValue | ConsumerParameterCapabilities.SupportsAllValue)); provider.SetConsumerParameters(new ReadOnlyCollection<ConsumerParameter>(parameters)); } }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜