Connectable Web Parts – Important Topic

Page 636 – how to create your own connected web part

Two types of connections :

(1) Static – used when one of the web parts is not in the web part zone. (required to write a NON-ASP.NET web part, from Microsoft.Sharepoint)
(2) Dynamic – you should wite this in most circumstances.

**** One web part is provider, and the other is consumer. (think of this as master/detail) The two web parts must have a common interface to talk through. The connection need to have the ConnectionProvider and ConnectionConsumer attributes assigned to it.

In this example, we will have two web parts: If you select a name from the first web part, the second web part displays “How are you, ” + {name selected in 1st web part}.

New empty Sharepoint Project, farm solution, called ConnectedWebParts.

First we need to implement an interface.

Add an interface, and call it IAuthorProvider

In this provider we will provide a simple read-only property called AuthorName.

Must add a public.

This interface will be used for provider and consumer.

Create a Provider Web Part —

Add a new WebPart, call AuthorProviderWebpart. Code:

Create a new drop down, with values; AutoPostBack is true so to force a page refresh; implement the AuthorName read only property of the IauthorInterface.

Last step is to create the provider connection point. It’s a method that returns the IauthorProvider interface implemented by the web part.

Allow MultipleConnections = true, allow webpart to connect to more than one web parts.

Thisis all we need for the provider web part.

Create a Consumer Web Part —

Add another web part, called AuthorConsumerWebPart.

built and deployed but the exampleis not working. Need to find another one.

Advertisements
Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: