|
using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using CommunicationInterface;
namespace ConsumerWebPart
{
[Guid("ab395c89-1146-4964-9528-f42153bf5c06")]
public class ConsumerWebPart : System.Web.UI.WebControls.WebParts.WebPart
{
Label lblTitle;
Label lblResult;
///// the string info consumer from custom reciever //
ICommunicationInterface connectionInterface = null;
// The consumer webpart must define a method that would accept the interface as an parameter and must be decorated with ConnectionConsumer attribute
[ConnectionConsumer("Parameter1 Consumer", "Parameter1 Consumer")]
public void GetConnectionInterface(ICommunicationInterface _connectionInterface)
{
connectionInterface = _connectionInterface;
}
/////////////////////////////////////////////////////////
public ConsumerWebPart()
{
this.Title = "Consumer WebPart";
this.ExportMode = WebPartExportMode.All;
}
protected override void CreateChildControls()
{
base.CreateChildControls();
Table tbl;
TableRow row;
TableCell cell;
// A table for layout
tbl = new Table();
row = new TableRow();
cell = new TableCell();
// first row for title
cell.VerticalAlign = VerticalAlign.Middle;
cell.HorizontalAlign = HorizontalAlign.Center;
lblTitle = new Label();
lblTitle.Text = "This WebPart will recieve a parameter from a provider:";
cell.Controls.Add(lblTitle);
row.Controls.Add(cell);
tbl.Controls.Add(row);
//second row for result
row = new TableRow();
cell = new TableCell();
cell.VerticalAlign = VerticalAlign.Middle;
cell.HorizontalAlign = HorizontalAlign.Center;
lblResult = new Label();
//check the connectionInterface for recieving the parameter1
if (connectionInterface != null)
{
lblResult.Text = connectionInterface.Parameter1+" is recieved!";
}
else
{
lblResult.Text = "nothing is recieved!";
}
cell.Controls.Add(lblResult);
row.Controls.Add(cell);
tbl.Controls.Add(row);
//add table to webpart
this.Controls.Add(tbl);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.