2009-09-09 42 views
0
public class ToolPartGetLists : Microsoft.SharePoint.WebPartPages.WebPart, ICommunicationInterface 
{ 
    private bool _error = false; 

    //......... 

    protected override void CreateChildControls() 
    { 
     if (!_error) 
     { 
      try 
      { 
       ViewState["prodList"] = SelectedList; 
       //base.CreateChildControls(); 
       Office_Cp = (OfficeCPS)Page.LoadControl(@"/_controltemplates/OfficeCP/OfficeCP.ascx"); 
       this.Controls.Add(Office_Cp); 
       // Your code here... 
       //this.Controls.Add(new LiteralControl(this.MyProperty)); 
      } 
      catch (Exception ex) 
      { 
       HandleException(ex); 
      } 
     } 
    } 
} 

public class OfficeCPS : System.Web.UI.UserControl 
{ 
    //I want the value of Selected List here 
    public string prodDataList = ""; 
    //....... 
} 

我試過ViewState,不工作!!!從Web部件傳遞字符串到用戶控件

+0

我明白這個問題嗎? – Pradeep007 2009-09-09 20:15:31

回答

1

裏面的try您可以使用:

Office_Cp = (OfficeCPS)Page.LoadControl(@"/_controltemplates/OfficeCP/OfficeCP.ascx"); 
this.Controls.Add(Office_Cp); 
Office_Cp.prodDataList = SelectedList; 

如果這不起作用仔細注意你是如何處理ASP.NET lifecycle

另請注意,最好隱藏prodDataList後面的屬性或方法。