Connection Interface Implemented?

Jul 26, 2010 at 9:03 PM
Hi, I am trying to write a web part that sends values via a connection to this SP Visibility Web Part, but I keep getting the error, "the connection type is not compatible with any other web parts on the page". Which interface does this webpart implement? ICellConsumer? I am using this interface in my code, yet am still getting the error. Any ideas? Thanks
Coordinator
Jul 26, 2010 at 9:23 PM

Yes, ICellConsumer, so it should work with either IRowProvider or ICellProvider web parts.

From the source code (here on Codeplex):

public class SPVisibilityFilter : Microsoft.SharePoint.WebPartPages.WebPart, ICellConsumer
Have you tried connecting your web part to an out-of-the-box web part (such as the Image web part - just to see if you can make the connection).

 

Jul 27, 2010 at 4:10 PM
Edited Jul 27, 2010 at 4:14 PM

Thanks for the reply Joe, I dont know whats going on, but I cannot get this to connect. Here is my code: 

 

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;

using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.Office.Server;
using Microsoft.Office.Server.UserProfiles;

namespace RG.EPS.VisibilityFlagSetter.UI.WebControls.WebParts
{
    public interface ICellProvider
        {
            string FlagValue { get; }
        }

    [Guid("3761ee31-3b45-41b4-9e36-478a2f1b2da8")]
    public class SetterWebPart : Microsoft.SharePoint.WebPartPages.WebPart, ICellProvider
    {
        private bool _error = false;
        private string _flagProperty = null;
        string _flagValue = "";
        string _siteName = null;

        [Personalizable(PersonalizationScope.Shared)]
        [WebBrowsable(true)]
        [System.ComponentModel.Category("Configuration")]
        [WebDisplayName("User Profile Property")]
        [WebDescription("This is the internal name of a User Profile Property that you want to send to the Visibility Filter WebPart ")]
        public string FlagProperty
        {
            get
            {
                if (_flagProperty == null)
                {
                    _flagProperty = "HomeAddressVisibilityFlag";
                }
                return _flagProperty;
            }
            set { _flagProperty = value; }
        }


        public SetterWebPart()
        {
            this.ExportMode = WebPartExportMode.All;
        }

        /// <summary>
        /// Create all your controls here for rendering.
        /// Try to avoid using the RenderWebPart() method.
        /// </summary>
        protected override void CreateChildControls()
        {
            if (!_error)
            {
                try
                {

                    base.CreateChildControls();

                    string queryParam = this.Page.Request.QueryString["accountname"];

                    using (SPSite site = new SPSite("http://intranet.dev.xxx.com"))
                        {
                            ServerContext context = ServerContext.GetContext(site);
                            UserProfileManager upm = new UserProfileManager(context);

                            UserProfile up = upm.GetUserProfile(queryParam.ToLower());
                            PropertyCollection propCol = up.ProfileManager.Properties;

                            if (up != null && propCol != null)
                            {
                                _flagValue = up[FlagProperty].Value.ToString();
                            }
                        }

                    // Your code here...
                    this.Controls.Add(new LiteralControl(this.FlagProperty));
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                }
            }
        }
        
        public string FlagValue
        {
            get { return _flagValue; }
        }

        [ConnectionProvider("Visibility Flag","ICellProvider",AllowsMultipleConnections=true)]
        public ICellProvider GetFlag()
        {
            return this;
        }
        /// <summary>
        /// Ensures that the CreateChildControls() is called before events.
        /// Use CreateChildControls() to create your controls.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            if (!_error)
            {
                try
                {
                    base.OnLoad(e);
                    this.EnsureChildControls();

                    // Your code here...
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                }
            }
        }
        //just a test that the user profile value is being retrieved
        protected override void RenderContents(HtmlTextWriter writer)
        {

            writer.WriteLine("Test2");
            writer.WriteLine(FlagProperty + " : " + FlagValue);
           
        }

        /// <summary>
        /// Clear all child controls and add an error message for display.
        /// </summary>
        /// <param name="ex"></param>
        private void HandleException(Exception ex)
        {
            this._error = true;
            this.Controls.Clear();
            this.Controls.Add(new LiteralControl(ex.Message));
        }
    }
}

 Its pretty simple, any idea whats going on?

Jul 27, 2010 at 10:34 PM

I believe Ive recognized my error, would you webpart work with the IWebPartField interface?