欧非资源网:安全、免费、专业放心的资源下载站! 最新软件|软件分类

您的位置:欧非资源网 > 其他专区 > SharePoint > sharepoint custom webpart与custom webpart的联动方法

sharepoint custom webpart与custom webpart的联动方法

时间:2020-09-04 11:59作者:admin来源:未知人气:291我要评论(0)

前面我们提到关于sharepoint  如何扩展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="发送" οnclick="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.如下图:

sharepoint custom webpart与custom webpart的联动方法
 

4。配置webpart连接,如下图,选择连接,发送对象,将consumer勾上。

sharepoint custom webpart与custom webpart的联动方法
 

5。保存编辑页面,如下图

sharepoint custom webpart与custom webpart的联动方法
 

接下来我们再文本框输入:广州京微信息科技有限公司,点击发送,把这个值,传给Consumer这个webpart接收,如下图:

sharepoint custom webpart与custom webpart的联动方法
 

如果我们继续数据其它的值,例如https://www.office26.com ,如下图:

sharepoint custom webpart与custom webpart的联动方法
 

这次主要是记录一下,如何用webpart给另一个webpart提供参数值,也就是我们常说的,webpart与webpart联动,连接。

相关阅读 SharePoint中Office文件无法打开的解决方案如何快速生成SharePoint测试大文件如何查询SharePoint Library中空文件夹?如何快速备份SharePoint Farm Solution如何解决Event Viewer中SharePoint Error - Event ID 8321SharePoint 2016 CU安装失败,"Exception: The upgraded database schema doesn't match the TargetSchema"的解决方案InfoPath Error “此文档库已经被重命名或删除,或者网络问题导致文件无法保存…” 的解决方案SharePoint 2013 App概述How to Shrink SharePoint Content Database Log File?Project Web App Feature无法开启的解决方案

文章评论
发表评论

热门文章 SharePoint 2016 图文安装教程 后面有激活序列号、密钥分享[SharePoint入门教程]一SharePoint发展、工具及术语如何用 SharePoint Online创建团队网站?SharePoint Iframe 报错“此内容不能显示在一个框架中”

最新文章 SharePoint中Office文件无法打开的解决方案如何快速生成SharePoint测试大文件 如何查询SharePoint Library中空文件夹?如何快速备份SharePoint Farm Solution如何解决Event Viewer中SharePoint Error - Event ID 8321SharePoint 2016 CU安装失败,"Exception: The upgraded database s

人气排行 SharePoint 2016 图文安装教程 后面有激活序列号、密钥分享[SharePoint入门教程]一SharePoint发展、工具及术语如何用 SharePoint Online创建团队网站?SharePoint Iframe 报错“此内容不能显示在一个框架中”SharePoint 2013 安装图解 SharePoint安装步骤图解教程SharePoint 如何开启访问请求[SharePoint入门教程]一SharePoint概述[SharePoint入门教程]一创建SharePoint母版页

盖楼回复X

(您的评论需要经过审核才能显示)