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


  • email this article to a colleague
  • suggest an article

    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 another connected Web Part.

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

    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>

    publicoverridevoid PartCommunicationConnect(string interfaceName,

                      WebPart connectedPart,

                      string connectedInterfaceName,

                      ConnectionRunAt runAt)

    {

          //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 == "Ex1CellProviderInterface_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 8 - PartCommunicationConnect method

    The above code sample will determine whether it's connected, number of connected Web Parts, and the name of the connected Web Part.

    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 ending with "Init". For example: CellProviderInit. The Init parameters are used when a Web Part needs to provide information about itself to other Web Parts. The developer has the option to override this method.

    ///<summary>

    /// PartCommunicationInit

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

    ///----if they can.

    ///----## ICellProvider Example: fire "CellProviderInit"

    ///</summary>

    ///

    publicoverridevoid PartCommunicationInit()

    {

          //Is it connected

          if(webpartConnected)

          {

                //If there is a listener, send init event

                if (CellProviderInit != null)

                {

                //Need to create the args for the CellProviderInit event

                CellProviderInitEventArgs cellProviderInitArgs = new

    CellProviderInitEventArgs();

                                 

                //Set the FieldName

                cellProviderInitArgs.FieldName = cellName;

     

                //Set the Display Name

                cellProviderInitArgs.FieldDisplayName = cellDisplayName;

                                 

                //Fire the CellProviderInit event.

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

                //cell it will be receiving when CellReady is fired

    later.

                CellProviderInit(this, cellProviderInitArgs);

                }

          }

    }

    Figure 9 - PartCommunicationInit method

    Step 7 - Override the PartCommunicationMain Method

    This method passes the primary data to other connected Web Parts. This allows the Web Part to fire any other events from the interface, such as the CellReady event. The developer has the option to override this method.

    ///<summary>

    /// PartCommunicationMain

    ///----At this time, a part can fire any events that it wants to.

    ///----## ICellProvider Example: fire "CellReady"

    ///</summary>

    ///

    publicoverridevoid PartCommunicationMain()

    {

          //Is it connected

          if(webpartConnected)

          {

                //If there is a listener, send CellReady event

                if (CellReady != null)

                {

                //Need to create the args for the CellProviderInit event

                CellReadyEventArgs cellReadyArgs = new

    CellReadyEventArgs();

                //Set the Cell to the value of the Textbox text

                //This is the value that will be sent to the Consumer

                cellReadyArgs.Cell = InputBox.Text;

                           

                //Fire the CellReady event.

                //The Consumer will then receive the Cell value

                CellReady(this, cellReadyArgs);

                }

          }                

    }

    Figure 10 - PartCommunicationMain method

    The above code passes the string value in the text box to the Web Part it's connected to.

    Step 8 - Override the RenderWebPart Method

    RenderWebPart method is overridden by the 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 control to the output parameter specified.

    ///</summary>

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

    protectedoverridevoid RenderWebPart(HtmlTextWriter output)

    {

          //Make sure that all necessary child controls are created

          EnsureChildControls();

          //If an error occurs while trying to register the interface

          if(interfaceRegistrationError)

          {

                //There is no interfaces connected.

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

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

                           

                //Create a break

                output.RenderBeginTag(HtmlTextWriterTag.Br);

                output.RenderEndTag();

          }

          else

          {

                //If connected

                if(intNumberOfConnections > 0)

                {

                      //Create a header

                      output.RenderBeginTag(HtmlTextWriterTag.H4);

                      //Write the header test

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

    to ");

                      output.Write(connectedWebPartName);

                      output.RenderEndTag();

     

                      //Render the TextBox

                      InputBox.Enabled = true;

                      output.Write("Enter the text   ");

                      InputBox.RenderControl(output);

                      //Create a break

                      output.RenderBeginTag(HtmlTextWriterTag.Br);

                      output.RenderEndTag();                   

                      //Render the button

                      SubmitButton.Enabled = true;

                      SubmitButton.RenderControl(output);

                }

                else

                {

                      //There is no interfaces connected.

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

    Connected.Please select a Cell Consumer to enable

    the Text Box and the Button.</FONT>");

                      //Create a break

                      output.RenderBeginTag(HtmlTextWriterTag.Br);

                      output.RenderEndTag();

                      output.Write("Enter the text   ");

                      //Render the TextBox

                      InputBox.RenderControl(output);

                      //Create a break

                      output.RenderBeginTag(HtmlTextWriterTag.Br);

                      output.RenderEndTag();                   

                      //Render the button

                      SubmitButton.RenderControl(output);

                }    

          }

    }

    Figure 11 - RenderWebPart method

    The code is looking for any error that occurs 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 text box and button controls. The interface controls will be disabled at the first instance until the Web Part gets connected. When the Web Part is connected to a compatible consumer Web Part, the end user will be able to enter a value to the text box and click the button.

    Step 9 - Override the CreateChildControls Method

    This method creates all the user interface controls necessary for the Web Part, in this example, the text box and the button controls.

    ///<summary>

    /// Creates all the user interface controls necessary for the Web Part

    ///</summary>

    protectedoverridevoid CreateChildControls()

    {

          //Create The Text Bob

          InputBox = new TextBox();

          InputBox.ID = "InputBox";

          InputBox.Enabled = false;

          //Add to the Control List

          Controls.Add(InputBox);

     

          //Create the button

          SubmitButton = new Button();

          SubmitButton.ID = "SubmitButton";

          SubmitButton.Text = "Submit";

          SubmitButton.Enabled  = false;

          //Add to the control list

          Controls.Add(SubmitButton);

     

          SubmitButton.Click += new EventHandler(SubmitButtonClick);

    }

    Figure 12 - CreateChildControls method

    Upload ICellProvider Web Part

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


    Figure 13 - Upload the Cell Provider Web Part

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


    Figure 14 - Cell Provider Web Part

    The above Web Part indicates it's not connected to a consumer Web Part. The end user has the option to connect this provider Web Part with a compatible consumer 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. (.

    Figure 15 displays the Cell Provider Web Part connected to a Cell Consumer Web Part.


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

    It displays the title of the connected Web Part in the header section. In this case, it is connected to Cell Consumer Web Part. The Cell Consumer Web Part will consume the value entered in the text box.

    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

    Rate This Article

  • 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 25, 2004 - Developing Web Parts with the ICellProvider Interface
    Most default SharePoint Server Web Parts can be connected across organizations. The second article in this series shows how to develop connectable Web Parts that provide information to other Web Parts.
    [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]
    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