Question

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 = "";
    //.......
}

I tried ViewState, not working!!!

Was it helpful?

Solution

Inside the try you could use:

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

If this doesn't work pay careful attention to how you are handling the ASP.NET lifecycle.

Also note it would be better practice to hide prodDataList behind a property or method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top