Sharepoint 2010 Sharepoint 2010 Web部件通信-如何让使用者等待提供程序

Sharepoint 2010 Sharepoint 2010 Web部件通信-如何让使用者等待提供程序,sharepoint-2010,communication,Sharepoint 2010,Communication,我有一系列的web部件需要在SharePoint 2010中实现。数据提供者web部件使用UpdatePanel并异步进行web服务调用,这可能会很慢。为了简单起见,我在页面(图表)上放置了一个消费者web部件,它将使用消费者作为其数据提供者 我的问题是,我不能让消费者等待提供商——我会遇到各种各样的错误,但基本上都会返回到“没有可用的数据”。这可能是因为它是一个图表web部件,但这个问题也适用于我将要开发的其他自定义部件,因为它们将获取相同的数据 问题是:我如何在我的提供商准备就绪时将数据推送

我有一系列的web部件需要在SharePoint 2010中实现。数据提供者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;
        }

    }
}
[ToolboxItem(true)]
公共部分类ClarityProjectGeneral:System.Web.UI.WebControl.WebParts.WebPart,IWebPartTable
{
public DataTable ProjectVitals=new DataTable();用于web部件通信
//一串属性
受保护的覆盖无效OnInit(事件参数e)
{
碱基.奥尼特(e);
初始化控件();
//用于web部件通信
//初始化我们的数据表,这样图表就不会呕吐
DataColumn col=新的DataColumn();
col.DataType=typeof(字符串);
col.ColumnName=“Name”;
this.ProjectVitals.Columns.Add(col);
col=新数据列();
col.DataType=typeof(DateTime);
col.ColumnName=“开始”;
this.ProjectVitals.Columns.Add(col);
col=新数据列();
col.DataType=typeof(DateTime);
col.ColumnName=“结束”;
this.ProjectVitals.Columns.Add(col);
}
受保护的无效页面加载(对象发送方、事件参数e)
{
loading.Visible=true;
content.Visible=false;
}
public ClarityObjectClasses.Projects GetProject(字符串projectID)
{
Clarity.ClarityAbstractorProject ca=新Clarity.ClarityAbstractorProject(this.Username,this.Password);
Dictionary queryParams=新字典();
添加(“projectID”,projectID);
//用于进行web服务调用的类
ClarityObjectClasses.Projects响应=新建ClarityObjectClasses.Projects();
响应=ca.GetProject(查询参数);
返回响应;
}
受保护的无效计时器1_刻度(对象发送方,事件参数e)
{
if(this.ProjectID==null | | this.Username==null | | | this.Password==null)
{
lblConfigError.Visible=true;
lblConfigError.Text=“未设置一个或多个必需的配置值。请检查web部件配置。”;
panelProjectDetails.Visible=false;
}
其他的
{
loading.Visible=true;
content.Visible=false;
panelProjectDetails.Visible=true;
ClarityObjectClasses.Projects=GetProject(this.ProjectID);
//分配一组值
//用于web部件通信
LoadTable(projects.Project[0]);
Timer1.Enabled=false;
loading.Visible=false;
content.Visible=true;
}
}
/*图形-图表通信接口函数*/
用于web部件通信
受保护的void加载表(ClarityObjectClasses.Project)
{
DataRow行=ProjectVitals.NewRow();
行[“名称”]=project.Name;
行[“开始”]=project.Start;
行[“结束”]=project.finish;
this.ProjectVitals.Rows.Add(row);
}
公共属性描述集合架构
{
得到
{
返回TypeDescriptor.GetProperties(ProjectVitals.DefaultView[0]);
}
}
public void GetTableData(TableCallback)
{
回调(ProjectVitals.Rows);
}
公共布尔连接点已启用
{
得到
{
对象o=ViewState[“ConnectionPointEnabled”];
返回值(o!=null)?(bool)o:true;
}
设置
{
ViewState[“ConnectionPointEnabled”]=值;
}
}
[ConnectionProvider(“表格”,类型(TableProviderConnectionPoint),AllowsMultipleConnections=true]
公共IWebPartTable GetConnectionInterface()
{
归还这个;
}
公共类表ProviderConnectionPoint:ProviderConnectionPoint
{
public TableProviderConnectionPoint(MethodInfo回调方法、类型interfaceType、类型controlType、字符串名称、字符串id、bool allowsMultipleConnections)
:base(callbackMethod、interfaceType、controlType、name、id、allowsMultipleConnections)
{
}
公共覆盖布尔已启用(控制)
{
返回((ClarityProjectGeneral)控件).ConnectionPointEnabled;
}
}
}

不太明白,但如果有帮助
您不能在UpdatePanel中使用“可连接”web部件,

因为缺少相应的事件来绑定异步回调上的数据。

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


因此,我反映了XsltListViewWebPart(或者不管它的确切名称是什么),并发现有一个接口。这允许您指定依赖项并获得所需的正确延迟绑定。GetRequiresData表示在请求数据之前还有更多的连接需要使用。

因此,基本上您不能拥有一系列使用UpdatePanel并异步加载每个web部件的web部件