LinkedIn

Friday, June 18, 2010

Connected WebParts in WSS 3.0 and MOSS 2007

ASP.NET 2.0 web part connection framework contains a set of predefined interfaces and transformers for these predefined Consumer and Provider Interfaces.

The following is an overview of the predefined interfaces that are available in the ASP.NET 2.0


web part connections framework (all interfaces are located in the System.Web.UI.WebControls.

WebParts namespace):
 
• IWebPartField interface: This interface is used when web parts want to exchange a single


value. This interface is comparable to cell interfaces in the SharePoint 2003 web part connection

framework. Classes supporting the web part field interface are very suitable for

implementing data enhancement scenarios.

• IWebPartRow interface: This interface is used when web parts want to exchange a row of

information. This interface is comparable to row interfaces in the SharePoint 2003 web part

connection framework. Classes supporting the web part row interface are very suitable for

implementing master/detail scenarios.


• IWebPartTable interface: This interface is used when web parts want to exchange an entire

list of data (a set of rows). This interface is comparable to list interfaces in the SharePoint

2003 web part connection framework. Classes supporting the web part table interface are

very suitable for implementing alternate-view scenarios.

• IWebPartParameters interface: This interface is used when web parts want to exchange a

list of parameters (or, if you will, a property bag containing various values). This interface

is comparable to the ParamsOut interfaces of the SharePoint 2003 web part connection

framework.

ProviderWebPart:

namespace TestWebPartConnection


{

[ToolboxData("<{0}:ProviderWebPart runat=server>")]

[Guid("59bf0dbb-e31a-4d6b-8295-76f4def28470")]

public class ProviderWebPart : WebPart, IWebPartField

{

TextBox InputBox;

Button SubmitButton;



[ConnectionProvider("Web part Connection Provider")]

public IWebPartField GetWPConnectFieldProvider()

{

return this;

}

public void GetFieldValue(FieldCallback callback)

{

callback.Invoke(InputBox.Text);

}

public PropertyDescriptor Schema

{

get

{

return TypeDescriptor.GetProperties(this)["Web part Connection Provider"];

}

}





protected override void Render(HtmlTextWriter output)

{

//Make sure that all necessary child controls are created

//EnsureChildControls();

CreateChildControls();



//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);





}



///

/// Creates all the user interface controls necessary for the web part

///


protected override void 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);

}



private void SubmitButtonClick(object sender, EventArgs e)

{

}

}

}
 
Consumer Webpart:
 
namespace TestWebPartConnection


{

[ToolboxData("<{0}:ConsumerWebPart runat=server>")]

[Guid("18789938-92d3-40ca-bd44-014644f7c884")]

public class ConsumerWebPart : System.Web.UI.WebControls.WebParts.WebPart

{

TextBox txtBox;
string name = string.Empty;


public string Name

{

get { return name; }

set { name = value; }

}



public ConsumerWebPart()

{

}



[ConnectionConsumer("Web Part Consumer")]

public void GetWPConnectedProviderInterface(IWebPartField connectProvider)

{

FieldCallback callback = new FieldCallback(ReceiveField);

connectProvider.GetFieldValue(callback);

}



public void ReceiveField(object objField)

{

if (objField != null)

{

this.Name = (string)objField;

if (this.Name != "")

txtBox.Text = this.Name;

}

}


protected override void CreateChildControls()

{

base.CreateChildControls();

Label label = new Label();

label.Text = "Name:";

txtBox = new TextBox();

Controls.Add(txtBox);



// TODO: add custom rendering code here.



// this.Controls.Add(label);

}

}

}

No comments:

Post a Comment