sharepoint 2010 custom webpart与custom webpart的联动方法
来源:互联网 发布:台服剑灵人女数据库 编辑:程序博客网 时间:2024/05/16 06:31
前面我们提到关于sharepoint 2010 如何扩展webpart自定义属性边栏字段 custom webpart properties,这次主要是要实现,如果让一个webpart给另一个webpart传值。在sharepoint中,有提供了一种方法,就是用[ConnectionProvider("WebpartConnectionProvider")] 和[ConnectionConsumer("WebpartConnectionConsumer")],其中的ConnectionProvider这个属性是数据提供着,参数值代表显示名称;ConnectionConsumer这个属性是数据接收者,参数值也是代表显示名称。
实现这样的功能,有一下几个步骤。
1。新建一个Interface接口,IGetName.cs
public interface IGetName
{
string Name { get; set; }
}
2。新建两个个可视化部件,WebpartConnectionProvider和WebpartConnectionConsumer
WebpartConnectionProvider.ascx
<asp:TextBox ID="txtstr" runat="server"></asp:TextBox>
<asp:Button ID="BtnProvider"
runat="server" Text="发送" onclick="BtnProvider_Click" />
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
namespace WebpartBarTest.WebpartConnectionProvider
{
public partial class WebpartConnectionProviderUserControl : UserControl
{
public WebpartConnectionProvider WebPart { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
}
protected void BtnProvider_Click(object sender, EventArgs e)
{
WebPart.Name = txtstr.Text;
}
}
}
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
namespace WebpartBarTest.WebpartConnectionProvider
{
[ToolboxItemAttribute(false)]
public class WebpartConnectionProvider : WebPart, IGetName
{
// 当更改可视 Web 部件项目项时,Visual Studio 可能会自动更新此路径。
private const string _ascxPath = @"~/_CONTROLTEMPLATES/WebpartBarTest/WebpartConnectionProvider/WebpartConnectionProviderUserControl.ascx";
protected override void CreateChildControls()
{
WebpartConnectionProviderUserControl control = Page.LoadControl(_ascxPath) as WebpartConnectionProviderUserControl;
if (control != null)
{
control.WebPart = this;
}
Controls.Add(control);
}
string _Name = "";
public string Name
{
get { return _Name; }
set { _Name = value; }
}
[ConnectionProvider("WebpartConnectionProvider")]
public IGetName GetName()
{
return this as IGetName;
}
}
}
WebpartConnectionConsumer.ascx
传输过来的值是:<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
namespace WebpartBarTest.WebpartConnectionConsumer
{
[ToolboxItemAttribute(false)]
public class WebpartConnectionConsumer : WebPart
{
// 当更改可视 Web 部件项目项时,Visual Studio 可能会自动更新此路径。
private const string _ascxPath = @"~/_CONTROLTEMPLATES/WebpartBarTest/WebpartConnectionConsumer/WebpartConnectionConsumerUserControl.ascx";
public Label lbl;
protected override void CreateChildControls()
{
Control control = Page.LoadControl(_ascxPath);
lbl = (Label)control.FindControl("Label1");
if (providerWebPart != null)
{
lbl.Text =providerWebPart.Name;
}
Controls.Add(control);
}
public IGetName providerWebPart;
[ConnectionConsumer("WebpartConnectionConsumer")]
public void ReceiveName(IGetName provider)
{
providerWebPart = provider;
}
}
}
3。部署到网站上。在页面上添加这两个webpart.如下图:
4。配置webpart连接,如下图,选择连接,发送对象,将consumer勾上。
5。保存编辑页面,如下图
接下来我们再文本框输入:广州京微信息科技有限公司,点击发送,把这个值,传给Consumer这个webpart接收,如下图:
如果我们继续数据其它的值,例如http://www.kingwi.com ,如下图:
这次主要是记录一下,如何用webpart给另一个webpart提供参数值,也就是我们常说的,webpart与webpart联动,连接。
广州京微信息科技有限公司,微软sharepoint解决方案提供商。
- sharepoint 2010 custom webpart与custom webpart的联动方法
- Custom Sharepoint Document Library Search WebPart
- sharepoint 2010 如何扩展webpart自定义属性边栏字段 custom webpart properties
- sharepoint 2010 如何扩展webpart自定义属性边栏字段 custom webpart properties
- SharePoint2010: custom webpart与PerformancePoint Service之间的通信
- Sharepoint 2010 之 WebPart
- Sharepoint 2010 之 WebPart
- SharePoint 2010 BI:Chart WebPart
- 部署Webpart的方法
- SharePoint 2010部署项目后找不到WebPart的解决办法
- SharePoint 2010 Silverlight webpart 加载超时的问题
- How to add custom property in custom webpart using VS 2012
- WebPart
- webpart
- webpart
- 可视化开发sharepoint的ajax webpart
- SharePoint中自定义WebPart的部署
- 关于SharePoint部署Webpart的相关资源
- suse linux原创案例02: 系统下英文环境下显示中文内容
- Linux-网桥原理分析 .
- 前端在开发过程中可能用的一些简单的功能的收集
- CStatusBar和CStatusBarCtrl的区别以及使用注意事项
- dede sql 用法
- sharepoint 2010 custom webpart与custom webpart的联动方法
- Flex上传文件功能
- ubuntu 用户/用户组管理
- Some projects cannot be imported because they already exist in the workspace
- 一步到位设置linux系统时间
- 如何配置Visual Studio 2010中的ASP.NET MVC的单元测试的代码覆盖率
- 在oracle中计算时间差
- suse linux原创案例03: Give root password for maintenance
- 指针