2011-06-22 182 views
0

我有一系列需要在SharePoint 2010中實現的Web部件。數據提供者Web部件使用UpdatePanel並異步進行可能潛在的Web服務調用緩慢。爲了簡單起見,我在頁面(圖表)上放置了一個消費者Web部件,它將使用消費者作爲其數據提供者。Sharepoint 2010 Web部件通信 - 如何讓消費者等待提供商

我的問題是,我不能讓消費者等待提供者 - 我收到各種錯誤,但基本上都回到「沒有可用的數據」。這可能是因爲它是Chart 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; 
     } 

    } 
} 
+0

嗨,你怎麼樣?我準備做同樣的事情,並想知道是否有可能? – Tim

回答

0

不太瞭解,但是如果它可以幫助 不得使用「連接」網絡內部零件的UpdatePanel, 由於缺乏相應的事件綁定異步數據回電話。

+0

所以基本上你不可能有一系列的web部件全部使用UpdatePanel,並且將它們中的每一個異步加載爲數據級聯? – McFaddon

+0

使用「可連接WebParts」 - 不管怎樣,不保證您的Web部件將被放置在UpdatePanel中。如果它是你的自定義頁面,你可以在沒有「可連接」功能的情況下將所有Web部件放置在UpdatePanel 部分中。 –

0

我只是偶然發現了這一點。我試圖實現自定義Web部件的問題與我自己的證明完全相同。我將過濾器應用於我的web部件和列表,然後讓圖表消耗它們。我發現我的網頁部分發送了錯誤的數據,但列表web部分按預期工作。

因此,我反映了XsltListViewWebPart(或任何它的確切名稱),我發現有一個IConnectionData接口。這使您可以指定依賴關係並獲得所需的正確延遲綁定。 GetRequiresData指示在請求數據之前還有更多的連接需要使用。

相關問題