366 13.6 Connecting Web Parts
method that applies the changes made to the custom properties to the
Calendar control. The code is very straightforward; it basically sets the
Calendar controls Show Day Header field to the value stored in the
MyShowDayHeader custom property and sets the Calendar control’s Show
Grid Lines field to the value stored in the
MyShowGridLines custom property.
From a development and testing perspective, it is sometimes useful to
set the
WebBrowsableAttribute to true to test the functionality of your cus-
tom properties before you implement the custom editor part. Once you are
happy that the custom properties are behaving as expected within your Web
Part, you can then reset
WebBrowsableAttribute to false. If you build the
solution at this stage with the
WebBrowsableAttribute set to true, the cus-
tom properties appear in the tool pane under the miscellaneous editor part,
and you can check and uncheck the property values accordingly (Figure
13.58). Opening and closing the browser will show you that the values per-
sist in the tool pane.
Step 2: Creating the custom editor part
Now that we have the appropriate functionality applied to our Web Part, all
that remains is to create the custom editor part. The creation of the custom
editor part is separated into two tasks. First, we need to create the class that
we will use for our custom editor part, and then we must override the
CreateEditorParts method in the main Web Part class. Figure 13.59
shows the code involved in creating the
EditorPart class that hosts our cus-
tom properties. Lines 16 through 28 instantiates and creates the two check-
box controls required for the editor part. Lines 30 through 36 override the
SyncChanges method; the SyncChanges method sets the initial values for
the properties in the editor part. Lines 38 through 44 override the
ApplyChanges method; the ApplyChanges method is self-explanatory in
that it applies the changes triggered from clicking the Apply or OK buttons
in the Web Part tool pane.
Figure 13.60 shows the code required to override the
CreateEditorParts method. This method should be inserted before the
RenderContents method of the sample code listed in Figure 13.57. The
CreateEditorParts method retrieves the collection of editor parts associ-
ated with the Web Part, and adds an additional editor part titled Calendar
Settings to the collection. Figure 13.61 shows the resultant output.
13.6 Connecting Web Parts
Web Parts themselves are excellent vehicles for providing users with relevant
information, but their true potential lies in their ability to communicate with
each other. A Web Part connection typically has a provider and a consumer.
13.6 Connecting Web Parts 367
Chapter 13
The provider Web Part initiates the communication by providing some form
of information that is of interest to a consumer Web Part. For example, lets
suppose we have a simple form Web Part connected to a Shared Documents
Web Part on the home page of a team site. The form Web Part has the role of
the provider for the connection, so that when the user enters a name in the
form, the text is sent to the consumer Web Part, which in this scenario is the
Shared Documents Web Part. In the role of the consumer, the Shared Docu-
ments Web Part then consumes the name, and filters the Shared Documents
document library to display only those documents modified by the user that
match that name (Figure 13.62).
Figure 13.57
Creating custom
properties using C#.
368 13.6 Connecting Web Parts
Figure 13.58
Custom properties
with
WebBrowsable-
Attribute set to
true.
Figure 13.59
Creating Editor
Part Class (C#).
13.6 Connecting Web Parts 369
Chapter 13
When a Web Part is created, it does not automatically support connec-
tions; to provide this functionality, the Web Part itself has to implement a
number of interfaces, which we’ll cover shortly. You can determine whether
an existing Web Part supports connections by navigating to the Web Part
Figure 13.60
Overriding the
CreateEditorParts
method (C#).
Figure 13.61
Custom
Editor Part.
Figure 13.62
Form Web Part
filtering shared
documents
Web Part.
370 13.6 Connecting Web Parts
menu when in design mode. If the Connections menu is enabled, then the
Web Part supports connections. The actual type of connection that a Web
Part supports depends on a number of factors, including the type of Web
Part it is (i.e., whether it’s a server-side Web Part or a client-side Web Part),
the location of the Web Part (i.e., whether it is on the same Web Part page as
its connection Web Part), and whether it has exceeded the maximum num-
ber of connections permissible for the Web Part.
13.6.1 Connection Interfaces
The Web Part Framework that came with Windows SharePoint Services
2.0 and SharePoint Portal Server 2003 provided a standard set of connec-
Figure 13.63
SendUrl
IWebPartField
provider Web Part.

Get Microsoft SharePoint 2007 Technologies now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.