سؤال

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

وحاولت حالة العرض، لا يعمل!

هل كانت مفيدة؟

المحلول

داخل 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