Creating a Hello World Connectable Web Parts in SharePoint.

To write connectable web parts we need to do the following

First we need to define our own interface that will specify the data we want to pass from one web part to another.

The provider web part needs to do the following

  • Implement the interface.
  • Create a property which would be returning a reference to the interface.
  • The property should be decorated with ConnectionProvider attribute.

The consumer web part needs to do the following

  • It should contain the method which would receive the interface.
  • The method should be decorated with ConnectionConsumer attribute.

Keeping the above information in mind let’s start

 Create a new web part project within Visual Studio 2008. (HelloWorldConnectedWebPart)

Right click on the Project

Select Add New ItemàSharePointàWebPart.

Now rename the webpart1.cs and webpart2.cs class as  HWProviderWebPart and HWConsumerWebPart respectively.

Now right click the project and add a new interface class.

    public interface IStringData

    {

        string ProviderStringInfo { get; }

    }

Our Provider class should implement this interface and define one property which would be returning the reference to the interface.

[Guid(“56978c39-1958-4128-a979-b9feaf2feb46”)]

    public class HWProviderWebPart : WebPart, IStringData

    {

        public HWProviderWebPart()

        {

        }

        protected override void CreateChildControls()

        {                    

        }

        // the string info that would be passed to the consumer

        protected string myInfo = “Hello World”;    

        // implement the property defined in the interface

        public string ProviderStringInfo

        {

            get { return myInfo; }

        }     

        // create a property which would be returning the interface reference

        // decorate it with ConnectionProvider

        [ConnectionProvider(“String Provider”)]

        public IStringData ConnectionInterface()

        {

            return this;

        }

    }

 

Now let’s move to our Consumer Web Part.

[Guid(“3575c6de-e21a-4e5a-b7f0-fe1aa4844402”)]

    public class HWConsumerWebPart : System.Web.UI.WebControls.WebParts.WebPart

    {

        public HWConsumerWebPart(){

        }

        protected override void CreateChildControls(){      

        }

 

        IStringData myProviderInterface = null;

        // The Consumer class should define a method that would accept

        // the interface as an parameter

        // Should be decorated with ConnectionConsumer attribute

 [ConnectionConsumer(“String Provider”)]

        public void GetInterface(IStringData providerInterface)

        {

            myProviderInterface = providerInterface;

        }

 

        protected override void Render(HtmlTextWriter writer)

        {

            try

            {  

                // priting the value provided by provider web part

                writer.Write(myProviderInterface.ProviderStringInfo);

            }

            catch(Exception ex)

            {

                writer.Write(“Error info “ + ex.Message);

            }

        }   

    }

 

Now build the project. ( Remove errors if any)

Right click the project.

Select Properties – Debug — Start browser with url ( Specify the site where the web part should be deployed)

Right click the project and select Deploy.

After Deploy Succeeds ,

Go to site actions — Site Settings — WebParts( Inside galleries) –Click on New– Select both the Provider and consumer web part — Populate Gallery.

Go to your home page —  Edit page — Add both the web parts –Select the provider web part — Connections and Specify the connection.

That’s it..


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

41 thoughts on “Creating a Hello World Connectable Web Parts in SharePoint.”

  1. When I originally commented I clickd the “Notify me when new comments are added” checkbox
    and now each time a comment is added I get three emails wwith
    the same comment. Is there any way you can remove people from that service?
    Thanks a lot!

    Like

  2. The penis may possibly become firm up to the point of the plaque and remain soft beyond that point. In some instances, the patient might see a narrowed ‘b ottleneck’ or an ‘hourglass’ shape of the penis at the same time. The plaque can also avoid the penis from storing blood during erection. As a result of this, the patient may be unable to have intercourse because of a soft and curved penis.

    Like

  3. She must extend all his support and goodwill and strive to learn everything about the issue. Avanaphil is known as phophodiesterase is an inhibitor. At present, the most well-liked drugs that are orally taken for erectile dysfunction are Ciales, Levitra and Viagra to assist with erectile dysfunction. Levitra is effective for males of all ages, works quickly, and provides sexual vitality in males who are 1st time patients, or ones which have diabetes, mellitus or have undergone radical prostratectomy.

    Like

  4. The relationship between the thyroid and erectile dysfunction is not but clear, but considering that thyroid diseases, too as erectile dysfunction, are much more frequent amongst men over 60, findings suggest that aging may not play as large a role as previously believed.Even although scientists are working on causes of ED, treatment of erectile dysfunction has been really successful via the oral ED drugs.

    Like

  5. In the event you get an accident or injuries and inside the long run, you go for a surgery, and as a result the whole method damages on the different nerves that trigger erectile dysfunction, you will expertise such problems. Surgeries specifically on the bladder, rectal or prostrate cancer can enhance the chances of erectile dysfunction.

    Like

  6. Parkinson Illness (PD). Prostrate Cancer. When a man has Erectile Dysfunction, it is a symptom that there is certainly something wrong inside; it’s a fact that men with penile dysfunction are most likely to suffer from other disorders.

    Like

  7. As stated, there are numerous distinct levels and symptoms of Erectile Dysfunction, distinct in every single individual. So, what do these medications truly supply, and what kind of results need to one expect? 1 is to anticipate a lot of items from E.D. medications. Very first, of course, the medication will allow you to get an erection when necessary. Furthermore, your erections will likely be noticeably larger, thicker, and stronger. This feature can definitely be one to appreciate. Also, these drugs will provide you with more stimulating orgasms. They are able to stop premature ejaculation too. Last but not least, some of these medications will really give you control over when and when not to have an erection. Not only will the male user of these medications be a lot more active, but he will likely be enjoying the longer-lasting sex even far more. The correspondent will most surely really feel an improve in pleasure as well.

    Like

  8. The National Board of Wellness statistics revealed that 15 to 30 million males in the United States have an erectile disorder. There is no specific age bracket that will not suffer from erectile dysfunction. Statistics recorded that 5 million men over 40 complained about erectile dysfunction and around 15 to 25 million males who were 65 years and above suffered from erectile dysfunction too.

    Like

  9. Will frequently produce erectile failure before progressing to impact the heart. The heart’s coronary arteries are 1.5 – 2.0mm across; the penile arteries are 0.6 – 0.7mm in diameter Body third the size of the coronaries – and can turn into clogged sooner. Unless there is certainly a change in lifestyle, coronary artery illness may follow impotence inside several years.

    Like

  10. Temporary erectile dysfunction is fairly typical and is as a result not regarded as to be a severe dilemma. Nevertheless, if the condition persists, the psychological effects might be significant. Impotence can severely impact a healthy relationship and be the prime reason for extreme depression; this can become chronic if left untreated. When sexual dysfunction extends over a consistently prolonged time period, it might be assumed that a serious physical or emotional disorder could possibly be present.

    Like

  11. Even although only 20% of erectile dysfunction situations can be attributed to psychological cases, the aspects such as anxiety, guilt and depression can severely impact a man’s erection abilities. Some medicines are also known to cause erectile dysfunction; they are blood pressure medications, tranquilizers, antidepressants and sedatives.

    Like

  12. A modern lifestyle is an crucial contributing factor to Erectile Dysfunction. Physical exercise makes a advantageous impact on the cardiovascular method, and some investigation indicates that males who exercise frequently have a lower risk of Erectile Dysfunction.Sort of exercise plays an essential role One of the analysis studies have also showed an inverse relation between Erectile Dysfunction risk and high-density lipoprotein cholesterol levels but no impact from elevated total cholesterol levels.

    Like

  13. From ancient Chinese drugs to vacuum devices, lots of solutions for erectile dysfunction are resorted to by males. Some of the age-old therapies and herbs are absolutely nothing but snake oils plus a random concoction sold under glorious names. An additional option obtainable is urethral injections. These injections reported a success rate of 60%.

    Like

  14. Beware of commercial claims of its miraculous healing power and select a reliable brans study and read carefully its brochure even though keeping attention to its content, manufacture, number, date of expiration, dosage, guidelines and side effects. Variations of this drug are:caverject, edex, prostin VR injections and Muse suppositions.

    Like

  15. Normally speaking, the inability to develop or preserve an erection is called erectile dysfunction or impotence. It’s one of the most common male sexual troubles inside the globe. Erectile Dysfunction (ED) can be attributed to different factors like old age, medical condition, side effects of illicit drugs, stress, performance anxiety along with a few others.

    Like

  16. for me it is not working. i am getting error messgae
    Error 1 Inconsistent accessibility: parameter type ‘Connwebpartsample.IStringData’ is less accessible than method ‘Connwebpartsample.Consumerhelloworldwebpart.Consumerhelloworldwebpart.GetInterface(Connwebpartsample.IStringData)’

    Like

  17. i am getting below error message
    Inconsistent accessibility: return type ‘connectablewebpart.IUser’ is less accessible than method ‘connectablewebpart.ProviderWP.cs.ProviderWP.ConnProviderMethod()’.

    please tell me how to resolve. i am working on sharepoint2010.

    Like

  18. Getting error

    ‘HelloWorldConnectedWebPart.HWProviderWebPart’ does not implement interface member ‘HelloWorldConnectedWebPart.IStringData.ProviderStringInfo’

    Like

  19. ‘HelloWorldConnectedWebPart.HWProviderWebPart’ does not implement interface member ‘HelloWorldConnectedWebPart.IStringData.ProviderStringInfo’

    Like

  20. I can deploy the solution but get and an error “Object Refrence not set to an instance of the Object” when i try to add these webparts on the webpage.

    Like

  21. Nice – but how to consume data (in my custom webpart) from the out-of-the-box dataform web part.

    The kind of connection where you click a cell value (link) and the consumer web part shows items filteret by the recieved value ?

    Like

  22. I’m having problem on the consumer…

    -when deployed and refresh the page my consumer got this error
    “Error info The method or operation is not implemented”

    Like

  23. Please help, I received this error when building

    Error on HWProviderWebPart
    [ConnectionProvider(“String Provider”)]
    public IStringData ConnectionInterface()
    {
    return this;
    }

    Error 1 Cannot implicitly convert type ‘HelloWorldConnectedWebPart.HWProviderWebPart’ to ‘HelloWorldConnectedWebPart.IStringData’. An explicit conversion exists (are you missing a cast?)

    Like

    1. I had the same issue and didn’t implement the IStringData interface in the HWProviderWebPart class.

      Make sure you implement the IStringData interface with the HWProviderWebPart:
      public class HWProviderWebPart : System.Web.UI.WebControls.WebParts.WebPart, IStringData

      Like

Share your thoughts

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s