September 2007
Beginner
448 pages
10h 2m
English
A web part that can exchange data with another web part is connectable. You create a connectable web part by completing these major tasks:
Define an interface for the connection.
Implement the interface in the connection provider web part.
Add a connection point to the provider web part.
Add a connection point to the consumer web part.
The interface defines the type of data used by both the provider and consumer web parts. The following code shows a very simple interface for exchanging text data between web parts:
// 1) Interface used for text connections.
public interface ITextProvider
{
string TextConnection { get; }
}The web part providing the connection must implement this interface and supply a method that returns the connection point. The following code shows a very simple web part that provides a text connection:
[Guid("C4288D94-D8F0-4f8f-8443-3A40F05E6B92")] public class ConnectProvider : WebPart, ITextProvider // 2) Implement interface { // 2) Implement interface. #region ITextProvider Members public string TextConnection { // Return Text property. get { return this.Text; } } #endregion // 3) Add provider connection point. [ConnectionProvider("TextConnection")] public ITextProvider ConnectionProvider( ) { // Return this web part. return this; } // Web part UI. #region WebPart properties and controls const string defaulttext = ""; private string text = defaulttext; [Personalizable(PersonalizationScope.Shared)] [Category("Custom")] [WebBrowsable(true)] [WebDisplayName("Text")] ...