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

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 the ICellProvider Interface
By Gayan Peiris
Rating: 3.6 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article

    Table of Contents


    • Page 1
      • Introduction
      • Code Example
      • Step 1 - Create the ICellProvider Interface Class
      • Step 2 - Declare the Events
      • Step 3 - Override the EnsureInterfaces Method
      • Step 4 - Override the CanRunAt Method

    • Page 2
      • Step 5 - Override the PartCommunicationConnect Method
      • Step 6 - Override the PartCommunicationInit Method
      • Step 7 - Override the PartCommunicationMain Method
      • Step 8 - Override the RenderWebPart Method
      • Step 9 - Override the CreateChildControls Method
      • Upload ICellProvider Web Part
      • About the Author

    • download sample code

    Introduction

    An ICellProvider Interface Web Part connects to a developed Web Part using an ICellConsumer interface. An ICellProvider interface should only be used to provide a single value to a Web Part developed from an ICellConsumer interface. There is no transformer available when an ICellProvider interface Web Part connects with an ICellConsumer Web Part. It's a direct connection between the provider and consumer Web Parts.

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

    Coding Example

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

    There are nine steps to developing an ICellProvider Web Part. I will explain each one of them as I progress through the code example. The ICellProvider code example provides a single value to an ICellConsumer Web Part. The Web Part allows the user to enter a value to a text box. The value entered in the text box will be available for any connected Web Part. The code example Web Part will only run on the server side and is not supported on the client side.

    Step 1 - Create the ICellProvider Interface Class

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

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


    Figure 1 - The ICellProviderEX1 Web Part project

    By default, the above project will create a webpart1 class that inherits from the webpart base class. The developer may delete this webpart1.cs file from the project because this file won't be useful.

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


    Figure 2 - Creating ICellProvider Interface class

    This will create an ICellProvider interface class as displayed below.

    publicclass ICellProviderWebPart : Microsoft.SharePoint.WebPartPages.WebPart, ICellProvider

    {

    //Other code

    }

     

    Figure 3 - ICellProviderWebPart class inherited from the Webpart base class and implement the ICellProvider Interface

    Step 2 - Declare the Events

    The second step is to declare all the relevant events for the connection interface. There are two events relevant for the ICellProvider Interface. The CellProviderInit and CellReady event. The CellReady event occurs when the PartCommunicationMain method event handler runs.

    ///<summary>

    ///   Events required by ICellProvider

    ///</summary>

    publicevent CellProviderInitEventHandler CellProviderInit;

    Figure 4 CellProviderInit event

    ///<summary>

    ///   Events required by ICellProvider

    ///</summary>

    publicevent CellReadyEventHandler CellReady;  

    Figure 5 - CellReady 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 notifies the 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>

    ///

    publicoverridevoid EnsureInterfaces()

    {

    try

    {

                //Register the ICellProvider interface

     

                RegisterInterface("Ex1CellProviderInterface_WPQ_",

    //InterfaceName: Unique name of the interface

     

    "ICellProvider",

    //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

     

                "CellProviderClientInterface_WPQ_",

    //InterfaceClientReference: for client-side connections,

    //a string that is used as the identifier for the client-side object that implements this interface

     

    "Provider a single value from a Text Box",

    //MenuLabel: a general label for the interface

                //(used in Authoring Connections)

     

    "Pass the value entered in to the Text Box to the Consumer Web Part");

    //Description: an extended explanation of the

    //interface (used in Authoring Connections)

          }

          catch(SecurityException e)

          {

    //Display an error message if the Interface won’t register properly

    interfaceRegistrationError = true;

     

          }

    }

    Figure 6 - EnsureInterface and RegisterInterface methods.

    There is a possibility that Code Access Security may prevent registration to the interface if the Web Part is installed in the bin directory and does not contain proper trust levels that are enabled in the web.config file. It is recommended to use a try/catch block to handle any problems that may occur when registering an interface.

    In the above code, I am providing an interface name to the Web Part. The ICellProvider Web Part will run only on the server side supporting unlimited connections. I have entered a value to the client side interface reference even if I don't use it in my exercise. The developer has the option to enter an empty string value for the client side reference if he is not using it. The menu Label text will display on the menu bar of the Web Part when it is on the design view. It will explain the functionality of the Web Part. In catch section, I am using a Boolean value to indicate whether the interface registration was successful.

    RegisterInterface method takes following parameters.

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

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

    MaxConnections
    Sets how many connections can be formed on this interface. The 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 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 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 that are supported by the connection compatibility rules.

    Step 4 - Override the CanRunAt Method

    This method determines whether the Web Part can be run on server, client or both. CanRunAt method must definitely be overridden by providing a value for the 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>

    ///

    publicoverride ConnectionRunAt CanRunAt()

    {

          //This Web Part can run on the server

          return ConnectionRunAt.Server;

    }

    Figure 7 - CanRunAt Method

    Step 5 - Override the PartCommunicationConnect Method >>

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Other Articles
    Apr 21, 2005 - Building a FAQ Module for the ASP.NET Community Starter Kit
    This sample chapter from Packt Publishing's "Building Websites with the ASP.NET Community Starter Kit" illustrates how to build a new module on top of the existing code in the ASP.NET Community Starter Kit (CSK). Using a Frequently Asked Questions (FAQ) module as an example, it shows how creating a new module allows you to add entirely new features which integrate seamlessly with the rest of the framework.
    [Read This Article]  [Top]
    Oct 20, 2004 - Beyond the DataGrid: An Architectural View of the Data Source Model in ASP.NET 1.x and 2.0
    Dino Esposito discusses the differences between the DataGrid control in version 1.x and 2.0 of ASP.NET. In the process, he also builds an improved version of the 1.x control that can get you some of the new 2.0 features today.
    [Read This Article]  [Top]
    Aug 4, 2004 - Accessibility Improvements in ASP.NET 2.0 - Part 2
    Alex Homer continues to highlight some of the new ASP.NET 2.0 accessibility features. These features make it easier for visually impaired users to view and navigate Web sites and provide better support for alternative types of browsers and user agents.
    [Read This Article]  [Top]
    Jul 30, 2004 - Connectable Web Parts in SharePoint Portal Server 2003 - Part 1
    Most default SharePoint Server Web Parts can be connected across organizations. The first article in this series explains how to connect existing Web Parts using the connection Interface classes in the SharePoint architecture.
    [Read This Article]  [Top]
    Jul 27, 2004 - Accessibility Improvements in ASP.NET 2.0 - Part 1
    Alex Homer highlights some of the new ASP.NET 2.0 accessibility features. These features make it easier for visually impaired users to view and navigate Web sites and provide better support for alternative types of browsers and user agents.
    [Read This Article]  [Top]
    Jun 30, 2004 - Simplified and Extended Data Binding Syntax in ASP.NET 2.0
    Alex Homer discusses the simplification of, and extensions to, the ASP.NET 1.x data binding syntax, the new two-way data binding syntax for updating data sources, and the new syntax for binding to XML data in ASP.NET 2.0.
    [Read This Article]  [Top]
    May 18, 2004 - ASP.NET 2.0 Caching Features
    This article examines some of the new and exciting caching features in ASP.NET 2.0 and shows how to implement them in Web applications.
    [Read This Article]  [Top]
    May 11, 2004 - SharePoint Security and .NET Impersonation
    When implementing custom components that require access to restricted resources, implicit impersonation must be used. Jay Nathan shows how to create a class that makes using .NET Impersonation a snap.
    [Read This Article]  [Top]
    May 4, 2004 - Creating a Flexible Configuration Section Handler
    Jeff Gonzalez demonstrates how to create a flexible configuration section handler using C#. He provides a summary background of the .NET configuration system, explains why the system is useful, and shows how it can be extended.
    [Read This Article]  [Top]
    Apr 21, 2004 - Creating a Web Custom Control
    Conrad Jalali shows how to build Web custom controls by creating one that displays checkboxes in a categorized, hierarchical view.
    [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


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers