承接MOSS各种工作流开发 联系人:王先生.电话:18618405729QQ:252385878 QQ群:41696750 MSN:wanghao-3@hotmail.com

导航

MOSS编写连接的WebPart

       还记得以前在 03里面编写的可连接的WebPart?那是多复杂,多麻烦啊,还有注册事件哦,我相信。编写过03的WebPart可能对那个11步很了解把,现在我们来介绍在07里面编写连接的WebPart是多么简单的事情哦。在很多MOSS的实际开发中,连接的WebPart是很有用的哦,在这里我只介绍一个简单的DEMO,起一个头。。
首先是提供者类、、
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;

namespace ProviderDemo
{
    [Guid("6b3f0c10-a574-4181-a765-b5d1ad65cf1b")]
    public class ProviderDemo : System.Web.UI.WebControls.WebParts.WebPart, IWebPartField
    {
        public ProviderDemo()
        {
            this.ExportMode = WebPartExportMode.All;
        }

        private TextBox tb;
        private Button btn;

        protected override void CreateChildControls()
        {
            tb = new TextBox();
            Controls.Add(tb);
            btn = new Button();
            btn.Text = "Send!";
            Controls.Add(btn);
        }

        [ConnectionProvider("SendValue", AllowsMultipleConnections=true)]
        public IWebPartField SendObject()
        {
            EnsureChildControls();
            return this;
        }

        #region IWebPartField Members

        public void GetFieldValue(FieldCallback callback)
        {
            EnsureChildControls();
            callback(tb.Text);
        }

        public System.ComponentModel.PropertyDescriptor Schema
        {
            get { return null; }
        }

        #endregion
    }
}
这个接受类。。。

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;

namespace ConsumerDemo
{
    [Guid("f97a6359-35fe-4de6-a7ed-5bbbe3aa7fda")]
    public class ConsumerDemo : System.Web.UI.WebControls.WebParts.WebPart
    {
        public ConsumerDemo()
        {
            this.ExportMode = WebPartExportMode.All;
        }

        private Label lbl;
        private IWebPartField provider;

        protected override void CreateChildControls()
        {
            lbl = new Label();
            Controls.Add(lbl);
        }

        [ConnectionConsumer("GetObject")]
        public void RecvObject(IWebPartField prov)
        {
            provider = prov;
        }

        private void GetData(object fieldValue)
        {
            lbl.Text = Convert.ToString(fieldValue);
        }

        protected override void OnPreRender(EventArgs e)
        {
            if (provider != null)
            {
                provider.GetFieldValue(new FieldCallback(GetData));
            }
            base.OnPreRender(e);
        }
    }
}
大家看看,,是不是很简单,比03里面的可要简单多咯。。。

posted on 2007-06-19 09:46  A A  阅读(2791)  评论(1编辑  收藏  举报