WebPart Connection
CoderSource.net
WebPart Connection - Article by deepak.gupta
Level: BeginnerType: Article
Rating: Page: 1 of 2

Date: 8/26/2007 12:00:00 AM

Environment: IIS, ASP .NET, C# 2.0

A WebPart Connection is a mechanism for sharing or transferring data from one Web Part (called the provider) to another Web Part (called the consumer). it is the ability to expose an interface to a WebPart (Provider) that another WebPart (Consumer) can connect to and use it

Let's compare it with the real world example where one person wants to share some information with other person over telephone.


In the same way , WebParts share information with the help of WebPart connection.

Connection Elements Real World WebPart Connection
Provider Person 1 WebPart1
Consumer Person 2 Webpart 2 (Consumer)
ConnectionPoint1 TelephoneSet1 ProviderConnectionPoint
ConnectionPoint 2 TelephoneSet2 ConsumerConnectionPoint
Media Telephone wire  WebPartManager gets the information from one provider WebPart and give the information to consumer WebPart
Information Message Interface

 

Main Elements of   WebPart Connection

  • Connection Interface
  •  :- The contract shared between the provider and consumer. firstly identify what information the WebParts need to exchange, and then represent that in an interface . This interface will be servers as the communication contract to exchange  information  between WebParts. I

  • Connection types
  •                    Provider :-
                        - Control that provides data  information
                        - Implements a provider connection point
                        - Defines a call back that returns an instance of the interface
                        - One provider connection point can connect to any number of consumer connection points of the same type

                      Consumer :-
                       - Control that gets data
                       - Implements a consumer connection point
                       - Defines a call back that gets an instance of the interface return by provider
                       - One consumer connection point can connect to only one provider connection points of the same type
     

     

  • Connection
  •   To establish a communication channel between provider and consumer WebParts  so that they can  exchange required information as defined in communication contract. A connection is establish between two connection points

                          Connection Points :-
                           - ProviderConnectionPoint  :-   Connection point at provider end
                           - ConsumerConnectionPoint :- Connection point at consumer end.

    Essential Connection Class  in ASP .NET

    WebPart Controls Description
    WebPartManager Manages all connections between controls in the Web Parts zone on a page. One (and only one) WebPartManager control is required for every Web Parts page.
    WebPartZone control that contain the server controls involved in a connection.
    WebPartConnection Represents a connection, with references to the provider and consumer, and all the other required components of a connection.

     
    ConnectionPoint

    ProviderConnectionPoint

    ConsumerConnectionPoint
     
    The ConnectionPoint base class defines an object that is associated with a consumer or provider and contains the details necessary to exchange data. The ProviderConnectionPoint is associated with the provider, and the ConsumerConnectionPoint is associated with the consumer.

     

    ConnectionsZone Provides a UI that enables users to create run-time, dynamic connections between server controls.
    ConnectionConsumerAttribute

    [ConnectionConsumer("displayname", "connectionpointID")]

    Identifies the callback method in a server control acting as the consumer in a Web Parts connection, and enables developers to specify details about the consumer's connection point.
    ConnectionProviderAttribute

    [ConnectionProvider("displayname", "connectionpointID")]

    Identifies the callback method in a server control acting as the provider  in a Web Parts connection, and enables developers to specify details about the consumer's connection point.

    How Connection works

    Web Parts connections are based on a "pull" model of connectivity, where the consumer gets data from the provider

    1. Web Part Manager request interface to the provider by calling [ConnectionProvider] method.
    2. Web Part Manager get an interface from a provider
    3. Web Part manager give the interface to the consumer  by calling [ConnectionConsumer] method
    4. Consumer call provider via interface

    In each page request, the WebPartManager enumerates the connections that are defined. Then, for each connection, it calls the connection provider's [ConnectionProvider] method to retrieve an interface and passes the interface to the corresponding connection consumer by calling the consumer's [ConnectionConsumer] method. The connection consumer then makes calls through the supplied interface to fetch data from the connection provider, as shown in figure above.

    Now we are done with the basic of WebPart Connection. Lets start with an example .
     

    1 2

    You Can Rate this Article, if you are Logged In      
     

    More Links from CoderSource.net:

     
    Refer to a Friend:

    Your Details:

    Name:     e-mail:

    Friend Details:

    Name:    e-mail:    


    MENU
    Home
    MFC 
    C++
    .Net
    WIN32
    Programming
    Forum
    My Articles
    Add to Google
    Add to My Yahoo!
    Welcome to Codersource.Net Login | Register | Faq  

    SEARCH
    Google
     

    NOTES:


    Thanks for visiting our CoderSource.net. This site will be improved with more articles. Interested visitors can also submit their articles through the Submit Article link.Your article will also be published after due consideration by the editor. 

    © Copyright 2003. All rights on content reserved by CoderSource.net. Contact    About Us