asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search





Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Developing Web Parts with ICellConsumer Interface
By Gayan Peiris
Rating: 3 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article

    Table of Contents

    • Page 1

      • Introduction
      • Coding Example
      • Step 1 – Create the ICellConsumer Interface Class
      • Step 2 – Declare the ICellConsumer Event
      • Step 3 – Override the EnsureInterfaces Method
      • Step 4 – Override the CanRunAt Method
      • Step 5 – Override the PartCommunicationConnect Method

    • Page 2

      • Step 6 – Override the PartCommunicationInit Method
      • Step 7 – Override the GetInitEventArgs Method
      • Step 8 – Override the CellProviderInit Event Handler
      • Step 9 - Override the CellReady Event
      • Step 10 – Override the RenderWebPart Method
      • Step 11 – Override the CreateChildControls Method
      • About the Author

    • Download Sample Code

    Introduction

    A Web Part developed using ICellConsumer interface connects to a Web Part developed using ICellProvider or IRowProvider interface. ICellConsumer interface should only be used to consume a single value from a Web Part developed using ICellProvider or IRowProvider interface. There is no transformer available when ICellConsumer interface Web Part connects with ICellProvider Web Part. It is a direct connection between the provider and consumer Web Parts. Connecting the ICellConsumer interface with IRowProvider interface, a transformer will display automatically allowing the user to map the column in row to appropriate cell. In this scenario, the end user will do the mapping rather than the consumer Web Part.

    Please visit "Connectable Web Parts in SharePoint Portal Server 2003" for more details regarding Connection Interfaces.

    Coding Example

    The developer should be familiar with developing basic Web Parts in SharePoint environment using Visual Studio.NET. Please visit "How to develop Web Parts for SharePoint 2003" for more information regarding developing Web Parts.

    There are eleven steps to complete when developing an ICellConsumer Web Part. I will explain each one of them as I progress through the code example. The ICellConsumer code example consumes a single value from an ICellProvider Web Part. This Web Part may be used to connect to an IRowProvider interface if needed. The Web Part contains a label control that renders the value received from a provider Web Part. The code example Web Part will only run on the server side and is not supported on client side.

    Step 1 – Create the ICellConsumer Interface Class

    The first step is to create a Web Part project that contains an ICellConsumer interface class. The Web Parts Template provided by Microsoft contains a template to create ICellConsumer interface class.

    I am creating a Web Part project called ICellConsumerEx1 as displayed below.


    Figure 1 - The ICellConsumerEx1 Web Part project

    By default, the above project will create a webpart1 class inherit from webpart base class. Developer may delete this webpart1.cs file from project because this file will not be useful.

    Right click on ICellConsumerEx1 project and select Add | Add New Item from the dropdown menu. This will display the Add New Item dialog box. Select Consumer Web Part from Template section. Enter a name and click the Open button.


    Figure 2 - Creating ICellConsumer Interface class

    This will create an ICellConsumer interface class as displayed below:

    publicclassICellConsumerWebPart : Microsoft.SharePoint.WebPartPages.WebPart , ICellConsumer

    {

    //Other code

    }

    Figure 3 - ICellConsumerWebPart class inherited from the Webpart base class and implement the ICellConsumer Interface

    Step 2 – Declare the ICellConsumer Event

    The second step is to declare all the relevant events for the connection interface. There is one event relevant for ICellConsumer Interface; the CellConsumerInit event.

    ///<summary>

    ///   Events required by ICellConsumer

    ///</summary>

    publiceventCellConsumerInitEventHandlerCellConsumerInit;

    Figure 4 - CellConsumerInit event

    Step 3 – Override the EnsureInterfaces Method

    This is a member of the Webpart base class. The method is called before the Web Part renders. This method provides notification to connectable Web Part that it should register its interfaces by using the RegisterInterface method. EnsureInterface method should be definitely overridden when developing connectable Web Parts. The RegisterInterface method occurs within the EnsureInterface method.

    ///<summary>

    ///EnsureInterfaces

    ///----Notification to the Web Part that is should ensure that all

    ///----its interfaces are registered using RegisterInterface.

    ///</summary>

    ///

    publicoverridevoidEnsureInterfaces()

    {

    try

    {

                //Register the ICellProvider interface

     

                RegisterInterface("Ex1CellConsumerInterface_WPQ_ ",

                //InterfaceName: Unique name of the interface

     

                " ICellConsumer ",

                //InterfaceType: The type of the interface

               

                WebPart.UnlimitedConnections,

                //MaxConnections: sets how many connections can

                //be formed on this interface

     

                ConnectionRunAt.Server,

                //RunAtOptions: where the interface can be run

     

                this,

                //InterfaceObject: reference to the actual

                //object that implements this interface

     

                " CellConsumerClientInterface_WPQ_ _",

                //InterfaceClientReference: for client-side connections,

                //a string that is used as the identifier for the client-

                //side object that implements this interface

     

                " Cell Consumer ",

                //MenuLabel: a general label for the interface

                //(used in Authoring Connections)

     

                " Consumes a string from a Text Box ");

                //Description: an extended explanation of the

                //interface (used in Authoring Connections)

          }

          catch(SecurityException e)

          {

                //Display an error message if the Interface will

                //not register properly

                interfaceRegistrationError = true;

          }

    }

    Figure 5 - EnsureInterface and RegisterInterface methods.

    There is a possibility that code access security may prevent the interface being registered if the Web Part is installed in the bin directory and not contain proper trust levels enabled in web.config file. It is recommended to use try/catch block to handle any problems may occur when registering an interface.

    RegisterInterface method takes following parameters.

    InterfaceName
    This is a friendly name of the interface. It should be a string property with unique value.

    InterfaceType
    The interface type. (Ex: ICellProvider, ICellConsumer, etc)

    MaxConnections
    Sets how many connections can be formed on this interface. Developer can select either LimitOneConnection allowing single connection or UnlimitedConnections allowing maximum connection limit.

    RunAtOption
    Where the interface can be run. (Ex: Client, Server, ClientAndServer, None)

    InterfaceObject
    Reference to the actual object that implements the interface.

    InterfaceClientReference
    This is a string value that will be used as the identifier for the client side object, which implements that interface.

    MenuLable
    The value that the developer enters here will appear in the connection menu user interface. It is a good practice to mention whether this is a “Provider” or “Consumer” Web Part in this section to indicate the direction of the dataflow.

    Description
    A description about the interface.

    There is one more parameter supported by RegisterInterface method. The allowCrossPageConnection parameter indicates whether this interface supports the cross page connections. By default, this parameter is set to True for all connection interfaces supported by the connection compatibility rules.

    Step 4 – Override the CanRunAt Method

    This will determine whether the Web Part can be run on server, client or both. This method must definitely override by providing value for ConnectionRunAt enumerator.

    ///<summary>

    ///CanRunAt

    ///----Called by the framework to determine whether a part thinks

    ///----that it can be run on the client or server based on the

    ///----current configuration.

    ///</summary>

    ///

    publicoverrideConnectionRunAtCanRunAt()

    {

          //This Web Part can run on the server

          returnConnectionRunAt.Server;

    }

    Figure 6 - CanRunAt Method

    Step 5 – Override the PartCommunicationConnect Method

    This method informs whether the Web Part is connected and which Web Part it is connected to. All connectable Web Parts must override this method.

    PartCommunicationConnect method takes several parameters.

    InterfaceName
    The Friendly name of the interface that is being connected.

    ConnectedPart
    A reference to other Web Part connected to.

    ConnectedInterfaceName
    The friendly name of the other Web Part interface connected.

    RunAt
    Where the interface can be executed.

    ///<summary>

    ///PartCommunicationConnect

    ///----Notification to the Web Part that it has been connected.  The

    ///----framework uses this to inform a part that it is connected as

    ///----soon as it connects up the appropriate events for the connection.

    ///</summary>

    publicoverridevoidPartCommunicationConnect(stringinterfaceName,

                      WebPartconnectedPart,

                      stringconnectedInterfaceName,

                      ConnectionRunAtrunAt)

    {

          //Must be a server-side part so need to create the Web Part's

    controls

          EnsureChildControls();

     

          //Count the number of connections for this particular Interface

          if(interfaceName == "Ex1CellConsumerInterface_WPQ_")

          {

                //The web part is connected

                webpartConnected = true;

                //Increase the count of the connections

                intNumberOfConnections++;

                //The connected web part name

                connectedWebPartName =

                SPEncode.HtmlEncode(connectedPart.Title);

          }

    }

    Figure 7 - PartCommunicationConnect method

    Above code sample will determine whether it has connected, count of connected Web Parts and the name of the Web Part connected to.

    Step 6 – Override the PartCommunicationInit Method >>

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Other Articles
    Jul 28, 2005 - N-Tier Web Applications using ASP.NET 2.0 and SQL Server 2005 - Part 2
    In the second part of his series on building N-tier web applications using ASP.NET 2.0 and SQL Server 2005, Thiru Thangarathinam covers the business logic and user interface layers. In the process, he also examines some new features in ASP.NET 2.0 that greatly simplify the development process.
    [Read This Article]  [Top]
    Jul 14, 2005 - An Innovative Technique for Creating Reusuable Page Templates in ASP.NET 1.x
    Code reusuability is one of the major goals of any good object-oriented programmer. While the ASP.NET framework has made code reusuability easier and more elegant than it was in classic ASP, one area where reusuability could be improved is at the UI level. This article outlines a technique that you can use in ASP.NET 1.x that allows every page in your web application to inherit not only the functionality of a base page, but its UI as well.
    [Read This Article]  [Top]
    Jun 23, 2005 - Monitoring SharePoint Usage through an ASP.NET Web Application
    In this article, Gayan Peiris looks at creating an ASP.NET web application that will display the usage details of a selected SharePoint site. Building such an application enables SharePoint administrators to gather all SharePoint usage data from a central location.
    [Read This Article]  [Top]
    May 12, 2005 - Retrieving SharePoint Site Information in an ASP.NET Web Application
    In this article, Gayan Peiris examines using the SharePoint Object Model to access SharePoint site information from an ASP.NET web application. It should be of particular interest to SharePoint administrators who can use the included code as a starting point for development of their own web-based SharePoint administration application.
    [Read This Article]  [Top]
    Dec 23, 2004 - Automated Deployment for Side By Side .NET Web Apps for Visual Studio .NET 2003
    In this article, David Every outlines a step-by-step account of how he solved the problems he encountered while implementing an auto-deployment process. He also describes how to create a stable process for automated remote .NET deployment featuring "side-by-side" capability.
    [Read This Article]  [Top]
    Aug 10, 2004 - Implementing and Promoting Daily Builds
    Automatic daily builds is a well known software engineering best practice. This article introduces a strategy for implementing and promoting daily builds and offers tips and tricks for preventing and fixing breaks.
    [Read This Article]  [Top]
    Jun 21, 2004 - Using Open Source .NET Tools for Sophisticated Builds
    Building an application can be more than pressing F5. With an increasing number of quality packages being released, developers for the .NET platform now have options to create a very sophisticated build process. Aaron Junod describes a sample build environment and shows how a number of tools can work together to make reliable, predictable, and value-added builds.
    [Read This Article]  [Top]
    Jun 24, 2003 - Programming for the Palm Part 1 - Creating the Palm Application
    The first part of this three part series walks through the process of creating a mobile blog application using a BASIC development environment for Palm OS devices called NS Basic. Subsequent articles will focus on synchronizing the data to the desktop using C# and creating an installer.
    [Read This Article]  [Top]
    Jun 18, 2003 - Online Database Functions Testing Tool
    This short article provides source code for a classic ASP online database functions testing application and shows how to configure and use the tool for either SQL Server or Oracle.
    [Read This Article]  [Top]
    May 22, 2003 - Rewrite.NET -- A URL Rewriting Engine for .NET
    In this article Robert Chartier shows you how to use functionality in the .NET Framework to rewrite requested URLs on the fly.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry



    JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers