Connecting web parts: The easy wayOctober 9, 2008 17:38
Since Moss2007 you can implement your own connection interface which enables you to connect customized web parts. It looks like you can basically transfer any serializable information. The first thing you have to do is to define a very simple interface. The second step is to inherit the interface at the web part class that sends the information. In this class you’ll have to assign the interface as the connection interface. The last step in the provider web part is to include the “get function” described by the interface to pass the value. In our consumer web part we have to retrieve the connection interface. Once this connection has been setup we can read and use the given value. In the example code we will use the interface with the name “IMossStringConnection” to pass a string value. Our web part and interface that provides our custom value:
namespace Sample.Code
{ /// /// Our custom interface /// public interface IMossStringConnection { string ProvidedString { get;} } /// //We start our connection provider here. The property name is the name //function to provide our value
And here is the code for the web part that consumes the provided value:
namespace Sample.Code
{ /// /// Web Part to consume the value /// public class ConsumerWebPart : WebPartBase { ….WEB PART CODE…. IMossStringConnection m_providerPart = null; /// //We start our connection consumer here. The property name is the name And that’s basically all the code you need to implement. Just copy and paste it in your web parts and have some fun! Tags: code example, connect, consumer, interface, provider, string value, web part.No Comments »No comments yet. RSS feed for comments on this post. TrackBack URL Leave a comment |
||