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,没有工作!!!

有帮助吗?

解决方案

try 中,你可以使用:

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

如果这不起作用,请特别注意您如何处理 ASP.NET生命周期

另请注意,最好将 prodDataList 隐藏在属性或方法后面。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top