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 -- Cont'd
By Gayan Peiris


  • 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

    Step 6 – Override the PartCommunicationInit Method

    This method is called when the Web Part needs to fire any initialization events. The Web Part will fire any event end with "Init" . For example CellConsumerInit. The Init parameters are used when a Web Part needs to provide information about itself to other Web Parts. The developer has the option whether to override this method or not.

    ///<summary>

    ///PartCommunicationInit

    ///----At this time, a part should fire any events that end with 'Init'

    ///----if they can.

    ///----## ICellConsumer Example: fire "CellConsumerInit"

    ///</summary>

    publicoverridevoidPartCommunicationInit()

    {

    //If the connection wasn't actually formed then don't want to send Init event

          if(_cellConnectedCount > 0)

          {

                //If there is a listener, send init event

                if (CellConsumerInit != null)

                {

                //Need to create the args for the CellConsumerInit event

                CellConsumerInitEventArgscellConsumerInitArgs = new

                CellConsumerInitEventArgs();

                                 

                //Set the FieldName

                cellConsumerInitArgs.FieldName = cellName;

                                 

                //Fire the CellConsumerInit event.

                //This basically tells the Provider Web Part what type of

                //cell the Consumer is expecting in the CellReady event.

                CellConsumerInit(this, cellConsumerInitArgs);

                }

          }

    }

    Figure 8 - PartCommunicationInit method.

    Step 7 – Override the GetInitEventArgs Method

    This method is used by SharePoint architecture to collect the necessary information it needs to build the transformer dialog. A transformer dialog box will come into action when ICellConsumer interface connect with IRowProvider interface. This method should only be implemented with interfaces that participate in transformer dialog box.

    publicoverrideInitEventArgsGetInitEventArgs(stringinterfaceName)

    {

    //Check if this is my particular cell interface

          if (interfaceName == "Ex1CellConsumerInterface_WPQ_")

          {

                EnsureChildControls();

                //Need to create the args for the CellConsumerInit event

                CellConsumerInitEventArgscellConsumerInitArgs = new

                CellConsumerInitEventArgs();

                                 

                //Set the FieldName

                cellConsumerInitArgs.FieldName = cellName;

                                 

                //return the InitArgs

                return(cellConsumerInitArgs);

          }

          else

          {

                return(null);

          }

    }

    Figure 9 - GetInitEventArgs method

    Step 8 – Override the CellProviderInit Event Handler

    The connected provider Web Part will use this method to pass initialization information to the consumer Web Part.

    ///<summary>

    /// The CellProviderInit event handler.

    /// The Provider part will fire this event during its

    /// PartCommunicationInit phase

    ///</summary>

    ///<param name="sender">Provider Web Part</param>

    ///<param name="cellProviderInitArgs">Theargs passed by the Provider

    ///   </param>

    publicvoidCellProviderInit(object sender, CellProviderInitEventArgscellProviderInitArgs)

    {

    //This is where the Consumer part could see what type of "Cell"

    //the Provider will be sending.

          connectedFieldName =

          SPEncode.HtmlEncode(cellProviderInitArgs.FieldDisplayName);

    }

    Figure 10 - CellProviderInit event handler

    The above code extract the field name of the provider Web Part connected.

    Step 9 - Override the CellReady Event

    The connected provider Web Parts will call this method during its PartCommunicationMain to pass its primary data to the consumer Web Part.

    publicvoidCellReady(object sender, CellReadyEventArgscellReadyArgs)

    {

    //Set the label text to the value of the "Cell" that was passed by the Provider

          if(cellReadyArgs.Cell != null)

          {

                displayLabel.Text  =cellReadyArgs.Cell.ToString();

          }

    }

    Figure 11 - CellReady event

    The label control in consumer Web Part receives a value from provider Web Part in above code.

    Step 10 – Override the RenderWebPart Method

    RenderWebPart method is overridden by webpart base class. This method is called by the Web Part architecture to render the HTML for the body of the Web Part.

    ///<summary>

    /// Render this Web Part control to the output parameter specified.

    ///</summary>

    ///<param name="output"> The HTML writer to write out to </param>

    protectedoverridevoidRenderWebPart(HtmlTextWriter output)

    {

          //Make sure all child controls are created

          EnsureChildControls();

                     

          if(interfaceRegistrationError)

          {

                //There is no interfaces connected.

                output.Write(" <FONT COLOR='RED'>An error occured while

                trying to register the interface.</FONT>");

          }

          else

          {

                //if cell connected

                if(_cellConnectedCount > 0)

                {

                      //Create a header

                      output.RenderBeginTag(HtmlTextWriterTag.H4);

                      //Write the header test

                      output.Write("Web Part is connected on Server Side");

                      output.Write(connectedWebpartName);

                      output.Write(" Web Part");

                      //Create a break

                      output.RenderBeginTag(HtmlTextWriterTag.Br);

                      output.Write("The field ");

                      output.Write(connectedFieldName);

                      output.Write(" is providing the information");

                      output.RenderEndTag();

                      //Create a break

                      output.RenderBeginTag(HtmlTextWriterTag.Br);

                      output.RenderEndTag();

                      //Render the button

                      displayLabel.RenderControl(output);                         }

                else

                {

                      //There is no interfaces connected.

                      output.Write(" <FONT COLOR='RED'>No Cell Providers

                      Connected. Please select a Cell Provider to display

                      value in the Label.</FONT>");

                }

          }

    }

    Figure 12 - RenderWebPart Method

    The code is looking for any errors that occur during the interface registration before rendering any controls. An error message will display if an error has occurred. Otherwise, if the Web Part is connected, the controls will be rendered with the information of the title of the connected Web Part and filed its consuming the data.

    Step 11 – Override the CreateChildControls Method

    This method creates all the user interface controls necessary for the Web Part. In this example, the Label control:

    ///<summary>

    ///Creates all the user interface controls necessary for the web part

    ///</summary>

    protectedoverridevoidCreateChildControls()

    {

          displayLabel = new Label();

          Controls.Add(displayLabel);

    }

    Figure 13 - CreateChildControls Method

    Uploading the ICellConsumer Web Part

    Navigate to SharePoint web page top right hand corner and select Modify My Page or Modify Shared Page depending on whether the end user in Personal or Shared view. Select Add Web Part | Import option. Browse to the "CellConsumerWebPart.dwp" file and click Upload button. This will upload the Cell Consumer Web Part as displayed below:


    Figure 14 - Upload the Cell Consumer Web Part.

    Drag and drop the "Cell Consumer Web Part" to the page as displayed below.


    Figure 15 - Cell Consumer Web Part

    The above Web Part indicates it is not connected to a Provider Web Part. The end user has the option to connect this consumer Web Part with a compatible provider Web Part any time. (Please refer to the article "Connectable Web Parts in SharePoint Portal 2003" for more information regarding how to connect a Web Part.)

    The following figure displays the Cell Consumer Web Part connected to a Cell Provider Web Part.


    Figure 16 - The Cell Consumer Web Part is connected to a Cell Provider Web Part

    It displays the title of the connected Web Part in the header section. In this case, it is connected to Cell Provider Web Part. The Consumer Web Part also display the information about the field that is connected in the provider Web Part.

    For more information regarding ICellProvider Web Parts, Please visit the article "Developing Web Parts with ICellProvider Interface".

    The above Cell Consumer code sample is a simple exercise to demonstrate the capability of a Cell Consumer Web Part. The developers can create more complex connectable Web Parts to suit their needs.

    About the Author

    Gayan Peiris is a Senior Consultant for Unique World Pty Ltd (www.uniqueworld.net) in Canberra, Australia. He is a MCSD with MCAD, MCP, Bcom and MIT certifications. Gayan has designed and developed Microsoft Web and Windows solutions since 1999. His expertise lies in developing scalable, high-performance applications with Microsoft Enterprise Server Products in .NET technology .His core skills are ADO.NET, ASP.NET, C#, VB.NET, Web Services, XML, SharePoint Portals, DNA and SQL Server.

    << Introduction

  • Other Articles
    Aug 31, 2005 - The X-Factor in SOA
    In this article, Joseph Poozhikunnel examines the importance of the three X's -- namely XML, XML Schema, and XSLT -- in a service oriented architecture (SOA). He then defines the design considerations that need to be adopted when designing a system based on SOA and examines the pitfalls that can arise if they're not followed.
    [Read This Article]  [Top]
    May 19, 2005 - Building an Enterprise Service Bus to Support Service Oriented Architecture
    In this article, Joseph Poozhikunnel defines an Enterprise Service Bus (ESB) that can be created to support any Service Oriented Architecture (SOA) adopted by an organization. The type of ESB required could vary as there is no "one size fits all", therefore the article examines a few of the mechanisms available that could be adopted to implement an ESB.
    [Read This Article]  [Top]
    Apr 14, 2005 - Building an End User Defined Data Model - Part 2
    In the seconmd part of his series on building an end user defined data model, Peter Scheffler gets into the actual meat of the model and discusses real-world implementation details and the actual table layouts.
    [Read This Article]  [Top]
    Mar 24, 2005 - Building an End User Defined Data Model - Part 1
    In the first article in this series, Peter Scheffler introduces the concept of a rules-based database engine that allows clients to make changes to their database structure without breaking the applications that access the database.
    [Read This Article]  [Top]
    Jan 19, 2005 - Developing a Simple Service Oriented Architecture
    The basic premise of a Service Oriented Architecture (SOA) system is to decouple applications from each other in order to make them autonomous. In this article, Joseph Poozhikunnel presents a simple SOA framework that can be used as a starting point for a system that addresses your specific business needs.
    [Read This Article]  [Top]
    Nov 3, 2004 - 10 Steps to a Successful Versioning and Deployment Strategy for .NET
    A well rounded versioning and deployment strategy considers several overlapping and interdependent .NET Framework concepts. In this article, Michele Leroux Bustamante will take you through a ten step program that reviews these core concepts, their relationship, and provides guidance for successful application deployments for the .NET Framework.
    [Read This Article]  [Top]
    Oct 27, 2004 - Business Intelligence with Microsoft SQL Server Reporting Services - Part 2
    Adnan Masood continues his discussion of Microsoft SQL Server Analysis services and Microsoft SQL Server Reporting services. In this part, he discusses the steps that go into building more advanced reports.
    [Read This Article]  [Top]
    Oct 13, 2004 - Business Intelligence with Microsoft SQL Server Reporting Services - Part 1
    Adnan Masood discusses Microsoft's comprehensive integrated business intelligence, data mining, analysis and reporting solution: Microsoft SQL Server Analysis services and Microsoft SQL Server Reporting services.
    [Read This Article]  [Top]
    Dec 15, 2003 - Realizing a Service-Oriented Architecture with .NET
    Chip Irek examines the architectural issues and component design issues of building a .NET application in a service-oriented architecture.
    [Read This Article]  [Top]
    Oct 21, 2003 - Achieving Reuse in ASP .NET - Part 1: Barriers to Reuse
    The importance of reuse can't be overstated, especially in light of the degree to which we go out of our way to avoid it, but implementing a reuse strategy means creating high-quality low-cost applications that just might save your job.
    [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

    Solutions
    Whitepapers and eBooks
    Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
    Avaya Article: How to Feed Data into the Avaya Event Processor
    Microsoft Article: Install What You Need with Win Server ‘08
    HP eBook: Putting the Green into IT
    Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
    Avaya Article: Setting Up a SIP A/S Development Environment
    IBM Article: How Cool Is Your Data Center?
    Microsoft Article: Managing Virtual Machines with Microsoft System Center
    HP eBook: Storage Networking , Part 1
    Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
    MORE WHITEPAPERS, EBOOKS, AND ARTICLES
    Webcasts
    Intel Video: Are Multi-core Processors Here to Stay?
    On-Demand Webcast: Five Virtualization Trends to Watch
    HP Video: Page Cost Calculator
    Intel Video: APIs for Parallel Programming
    HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
    Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
    MORE WEBCASTS, PODCASTS, AND VIDEOS
    Downloads and eKits
    Sun Download: Solaris 8 Migration Assistant
    Sybase Download: SQL Anywhere Developer Edition
    Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
    Red Gate Download: SQL Compare Pro 6
    Iron Speed Designer Application Generator
    MORE DOWNLOADS, EKITS, AND FREE TRIALS
    Tutorials and Demos
    How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
    eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
    IBM Article: Collaborating in the High-Performance Workplace
    HP Demo: StorageWorks EVA4400
    Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
    Microsoft How-to Article: Get Going with Silverlight and Windows Live
    MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES