【问题标题】:Sharepoint 2010 Web Part Communication - How to make consumer wait for the providerSharepoint 2010 Web 部件通信 - 如何让消费者等待提供者
【发布时间】:2011-09-20 10:31:26
【问题描述】:

我有一系列需要在 SharePoint 2010 中实现的 Web 部件。数据提供程序 Web 部件使用 UpdatePanel 并异步进行可能很慢的 Web 服务调用。为了简单起见,我在页面(图表)上放置了一个消费者 Web 部件,它将使用消费者作为其数据提供者。

我的问题是我无法让消费者等待提供者 - 我收到各种错误,但基本上都回到“没有可用数据”。这可能是因为它是一个图表 Web 部件,但这个问题也适用于我将开发的其他自定义部件,因为它们会提取相同的数据。

问题是:当我的提供者准备好时,我如何将数据推送给我的消费者,或者让他们等待我的提供者获得数据(通过轮询或其他方式)。

注意:这只是一个原型,我还没有添加错误处理等。

代码如下:

[ToolboxItem(true)]
public partial class ClarityProjectGeneral : System.Web.UI.WebControls.WebParts.WebPart , IWebPartTable
{

    public DataTable ProjectVitals = new DataTable(); For web part communication

    // bunch of properties

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        InitializeControl();

        // For web part communication
        // Initialize our datatable so the chart doesn't barf
        DataColumn col = new DataColumn();
        col.DataType = typeof(string);
        col.ColumnName = "Name";
        this.ProjectVitals.Columns.Add(col);

        col = new DataColumn();
        col.DataType = typeof(DateTime);
        col.ColumnName = "Start";
        this.ProjectVitals.Columns.Add(col);

        col = new DataColumn();
        col.DataType = typeof(DateTime);
        col.ColumnName = "End";
        this.ProjectVitals.Columns.Add(col);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        loading.Visible = true;
        content.Visible = false;            
    }

    public ClarityObjectClasses.Projects GetProject(string projectID)
    {
        Clarity.ClarityAbstractorProject ca = new Clarity.ClarityAbstractorProject(this.Username, this.Password);
        Dictionary<string, string> queryParams = new Dictionary<string, string>();
        queryParams.Add("projectID", projectID);
        // Class for making web service call
        ClarityObjectClasses.Projects response = new ClarityObjectClasses.Projects();
        response = ca.GetProject(queryParams);
        return response;
    }

    protected void Timer1_Tick(object sender, EventArgs e)
    {
        if (this.ProjectID == null || this.Username == null || this.Password == null)
        {
            lblConfigError.Visible = true;
            lblConfigError.Text = "One or more required configuration values are not set.  Please check the web part configuration.";
            panelProjectDetails.Visible = false;
        }
        else
        {
            loading.Visible = true;
            content.Visible = false;

            panelProjectDetails.Visible = true;
            ClarityObjectClasses.Projects projects = GetProject(this.ProjectID);
            //Assign a bunch of values

            // For web part communication
            LoadTable(projects.Project[0]);

            Timer1.Enabled = false;
            loading.Visible = false;
            content.Visible = true;
        }
    }


    /* Interface functions for Graph Chart communication */
    For web part communication
    protected void LoadTable(ClarityObjectClasses.Project project)
    {
        DataRow row = ProjectVitals.NewRow();
        row["Name"] = project.name;
        row["Start"] = project.start;
        row["End"] = project.finish;
        this.ProjectVitals.Rows.Add(row);
    }

    public PropertyDescriptorCollection Schema
    {
        get
        {
            return TypeDescriptor.GetProperties(ProjectVitals.DefaultView[0]);
        }
    }

    public void GetTableData(TableCallback callback)
    {
        callback(ProjectVitals.Rows);
    }

    public bool ConnectionPointEnabled
    {
        get
        {
            object o = ViewState["ConnectionPointEnabled"];
            return (o != null) ? (bool)o : true;
        }
        set
        {
            ViewState["ConnectionPointEnabled"] = value;
        }
    }

    [ConnectionProvider("Table", typeof(TableProviderConnectionPoint), AllowsMultipleConnections = true)]
    public IWebPartTable GetConnectionInterface()
    {
        return this;
    }

    public class TableProviderConnectionPoint : ProviderConnectionPoint
    {
        public TableProviderConnectionPoint(MethodInfo callbackMethod, Type interfaceType, Type controlType, string name, string id, bool allowsMultipleConnections)
            : base(callbackMethod, interfaceType, controlType, name, id, allowsMultipleConnections)
        {
        }

        public override bool GetEnabled(Control control)
        {
            return ((ClarityProjectGeneral)control).ConnectionPointEnabled;
        }

    }
}

【问题讨论】:

  • 嗨,你过得怎么样?我想做同样的事情,想知道这是否可能?

标签: sharepoint-2010 communication


【解决方案1】:

不太明白,但如果有帮助 您不能在 UpdatePanel 中使用“可连接”的 Web 部件, 因为在异步回调上没有对应的事件绑定数据。

【讨论】:

  • 所以基本上你不能让一系列 Web 部件都使用 UpdatePanel 并在数据级联时异步加载它们中的每一个?
  • 使用“可连接的 WebParts” - 不。无论如何,不​​能保证您的 Web 部件将放置在 UpdatePanel 中。如果它是您的自定义页面,您可以通过将所有 Web 部件放在 UpdatePanel 部分中来实现,而无需“可连接”功能。
【解决方案2】:

我只是偶然发现了这个。我在尝试实现自定义 Web 部件时遇到了完全相同的问题,只是为了证明自己。我将过滤器应用于我的 webpart 和列表,然后让图表使用它们。我发现我的 webpart 发送了错误的数据,但 list webpart 工作正常。

所以我反映了 XsltListViewWebPart(或任何它的确切名称),我发现有一个 IConnectionData 接口。这允许您指定依赖项并获得所需的正确延迟绑定。 GetRequiresData 表示在请求数据之前还有更多的连接需要消耗。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-11
    • 2012-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-24
    • 1970-01-01
    相关资源
    最近更新 更多