惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
T
Threat Research - Cisco Blogs
GbyAI
GbyAI
Y
Y Combinator Blog
美团技术团队
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 【当耐特】
S
SegmentFault 最新的问题
IT之家
IT之家
Recent Announcements
Recent Announcements
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
阮一峰的网络日志
阮一峰的网络日志
T
The Blog of Author Tim Ferriss
Martin Fowler
Martin Fowler
Microsoft Azure Blog
Microsoft Azure Blog
V
Visual Studio Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
U
Unit 42
WordPress大学
WordPress大学
博客园 - Franky
L
LangChain Blog
人人都是产品经理
人人都是产品经理
小众软件
小众软件
博客园 - 叶小钗
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
大猫的无限游戏
大猫的无限游戏
云风的 BLOG
云风的 BLOG
Vercel News
Vercel News
雷峰网
雷峰网
腾讯CDC
Google DeepMind News
Google DeepMind News
博客园 - 三生石上(FineUI控件)
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Help Net Security
Help Net Security
C
Check Point Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
N
News and Events Feed by Topic
V2EX - 技术
V2EX - 技术
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Schneier on Security
Schneier on Security
博客园 - 聂微东
A
Arctic Wolf
H
Heimdal Security Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
The Exploit Database - CXSecurity.com
C
Cyber Attacks, Cyber Crime and Cyber Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Google DeepMind News
Google DeepMind News

博客园 - Ken Lin

Oracle VS Sql Server Asp.net常用的一些代码(转) - Ken Lin - 博客园 Sharepoint工作流任务权限问题 MOSS开发Tips WSS 扩展文件夹属性-应用场景一 内容查询Web 部件定制 How to submit data in InfoPath form services Form Services方式发布带有Managed Code的表单模板 WSS 代码执行的权限提升 用代码访问InfoPath表单内容 STSADM 进行MOSS的备份与迁移 利用SharePoint Designer更改任务列表状态栏显示 MOSS 工作流(二)自定义开发 MOSS-自定义字段类型 通过Web Part Connection 在Web Part 之间传递数据(一) WebPart 生存周期 QuickPart中文字符显示问题 MOSS SP1 解决Ajax Extension 对Webpart的兼容性问题 MOSS 工作流(一)
通过Web Part Connection 在Web Part 之间传递数据(二)
Ken Lin · 2008-01-24 · via 博客园 - Ken Lin

发现网上关于Web Part Connection 的资料非常少现在,在这个Session我就为大家介绍一个
Web Part Connection 来实现Web Part之间数据传递的Sample

总结了下,实现Web Part Connection 的开发大概分为这么几步:

根据要传递的数据类型定义接口

创建一个实现接口的类

创建Provider Web Part,实现提供数据的方法

创建 Consumer Web Part,实现接收数据的方法

下面通过一个简单的demo 进一步了解Web Part Connection

首先我们创建一个"WebPartConnection” SharePoint Project,在项目里添加如下3 Class:

IMessage     是实现要传递数据的接口定义

public interface IMessage

    {

        String MessageContent{get;set;}

    }

并在里头定义了一个Message类,来实现IMessage接口

public class Message : IMessage

    {

        private string _sMessageContent=default(string);

        public string MessageContent

        {

            get{return _sMessageContent;}

            set{_sMessageContent = value;}

        }

    }

ProviderWP   数据提供Web Part, 实现提供数据的方法ReturnMessage()

[ConnectionProvider("Return the message")]

        public IMessage ReturnMessage()

        {

            this.EnsureChildControls();

            IMessage result = new Message();

            result.MessageContent = txtMessageBox.Text.Trim();

            return result;

        }

"ConnectionProvider Attribute" 标识了此方法就是Provider WP 用来提供数据的方法

ConsumerWP 数据接收Web Part, 实现接收数据的方法RecieveMessage ()

        [ConnectionConsumer("recieve the message")]       

        public void RecieveMessage(IMessage msg)

        {

            if (msg != null && msg.MessageContent != null)

            {

                OutputText = msg.MessageContent;

            }

        }

"ConnectionConsumer Attribute" 标识了此方法就是Consumer WP 用来接收数据的方法

最后,我们把开发好的Web Part 部署到SharePoint站点上,将ProviderWP ConsumerWP 

添加到同一个页面上,通过简单的配置就可以实现这俩个Web Part之间传递数据了.

部署Web Part步骤很简单在这里就不做介绍了.


源代码下载

这个例子,我们只是做了简单的值传递,并且在Comsumer WP 中直接简单地render,
如果我们要用到这个传递过来的值,实现更复杂的逻辑,那么你就要了解RecieveMessage这个方法它
在整个web part 生命周期里执行的顺序。例如这个方法的执行是在

CreateChildControls()之后,
Render()方法之前被执行的。清楚了这些,我们才能去开发更复杂的web part connection.