Connected web parts

Create an interface first and a property for that interface

public interface IQueryFilter

    {

        string FilterQuery { get; set; }

    }

Note: all the members created in Interface must be implemented in the class that inherits it.

Create two web parts.

One acts as connection provider and other act as connection consumer

In FilterWebPart inherit interface IQueryFilter as shown below

public partial class FilterWebPart : WebPart, IQueryFilter

 

once  interface is inherited it has to be implemented.

In FilterWebPart.acsx.cs

create a connection provider

[ConnectionProvider("Query Provider", "QueryProvider")]

        public IQueryFilter queryFilter()

        {

            return this;

        }

 

Create a property as shown below

 

        private string _FilterQuery;

        [Personalizable]

        public string FilterQuery

        {

            get

            {

                return this._FilterQuery;

            }

            set

            {

                this._FilterQuery = value;

            }

        }

[Personalizable] – it states that this property will be different to each user logged in system

On button click set the property value

protected void BtnSearch_Click(object sender, EventArgs e)

        {

            FilterQuery = "Test query";

        }

 

on button click value is assigned to FilterQuery property which is member of IQueryFilter interface.

Inherit IQueryFilter in TestWebPart.acsx.cs

public partial class FilterWebPart : WebPart, IQueryFilter

IQueryFilter queryFilter;// create an object for IQueryFilter interface

 

Now create a connection Consumer in TestWebPart.acsx.cs

        [ConnectionConsumer("Query Consumer", "QueryConsumer")]

 

        public void QueryConsumer(IQueryFilter provider)

        {

            if (provider != null)

            {

                this.queryFilter = provider;

                this.FilterQuery = queryFilter.FilterQuery;

            }

        }

 

//set the value for  FilterQuery which is a member of IQueryFilter interface

        private string _FilterQuery;

        public string FilterQuery

        {

            get

            {

                return this._FilterQuery;

            }

            set

            {

                this._FilterQuery = value;

            }

        }

 Deploy the webpart and connect the web parts as shown below

Copyrights 2017, www.expertsupdates.com