웹 부품에서 사용자 컨트롤로 문자열을 전달합니다
-
05-07-2019 - |
문제
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
속성이나 방법 뒤에.
제휴하지 않습니다 StackOverflow