1.建接口,接口文件结构为获得传递的参数。将按口文件拖进行强签名放到服务器的windows/assembly 下。
2.consumer部件:
[ToolboxItemAttribute(false)]
public class webcs : WebPart
{
Label lbl;
Iwebcon iwe = null;
[ConnectionConsumer("get param", "get param")]
public void getparam(Iwebcon _iweb) {
iwe = _iweb;
}
public webcs()
{
this.Title = "webcs";
this.ExportMode = WebPartExportMode.All;
}
protected override void CreateChildControls()
{
base.CreateChildControls();
lbl = new Label();
if (iwe != null)
{
lbl.Text = "GET.."+iwe.sendparam;
}
else
{
lbl.Text = "GET..";
}
this.Controls.Add(lbl);
}
}
}
3.provider部件:
[ToolboxItemAttribute(false)]
public class webprovider : System.Web.UI.WebControls.WebParts.WebPart,Iwebcon
{
protected string _sendparam = "";
public string sendparam
{
get { return _sendparam; }
}
TextBox txt;
Button btn;
[ConnectionProvider("sendparam", "sendparam")]
public Iwebcon connectionparam()
{
return this;
}
public webprovider()
{
this.Title = "Web Provider";
this.ExportMode = WebPartExportMode.All;
}
protected override void CreateChildControls()
{
base.CreateChildControls();
txt = new TextBox();
txt.Text = "";
btn = new Button();
btn.Text = "send...";
btn.Click+=new EventHandler(btn_Click);
this.Controls.Add(txt);
this.Controls.Add(btn);
}
void btn_Click(object sender, EventArgs e)
{
this._sendparam = txt.Text;
}
}
}
[assembly: CLSCompliant(false)]