2012-03-20 3 views
0

컨트롤이 있습니다 : 버튼을 정의하는 복합 컨트롤입니다. 이 단추는 컨트롤을 표시하기 전에 Command 이벤트를 호출하고 다른 컨트롤의 속성 값을 설정합니다.복합 컨트롤 사이의 값 전달

이러한 컨트롤은 모두 컨테이너 컨트롤에서 인스턴스화됩니다. CreateChildControls() 메서드 내에서 두 번째 형식의 속성 값을 가져와야하지만이 방법은 불가능합니다. 이유는 무엇입니까?

시나리오 :

public class Main : CompositeControl 
{ 
    #region fields 
    private StepPersonal _stepPersonal; 
    private StepFinancial _stepFinancial; 
    #endregion 

    protected override CreateChildControls() 
    { 
     this._stepPersonal = new StepPersonal { ID = "StepPersonal1", Visible = true }; 
     this.Controls.Add(this._stepPersonal); 
     this._stepFinancial = new StepFinancial { ID = "StepFinancial1", Visible = false }; 
     this.Controls.Add(this._stepFinancial); 
    } 

    protected override Render(HtmlTextWriter writer) 
    { 
     this._stepPersonal.RenderControl(writer); 
     this._stepFinancial.RenderControl(writer); 
    } 
} 

StepPersonal :

public class StepPersonal : CompositeControl 
{ 
    #region fields 
    private Button _checkDetails; 
    #endregion 

    protected override CreateChildControls() 
    { 
     this._checkDetails = new Button { ID = "CheckDetailsButton", Text = "CheckDetails", CommandName = "DetailsConfirmation" } 
     this._checkDetails.Command += new CommandEventHandler(this.OnCheckDetails); 
     this.Controls.Add(this._checkDetails); 
    } 

    protected override Render(HtmlTextWriter writer) 
    { 
     this._checkDetail.RenderControl(writer);   
    } 

    protected void OnCheckDetails(object sender, CommandEventArgs args) 
    { 
     string argument = args.CommandArgs.ToString(); 

     this.Visible = false; 
     Main owner = (sender as Button).FindParent<Main>(); // custom extension method 
     StepFinancial sf = owner.FindControl<StepFinancial>("StepFinancial1"); 
     sf.Argument = argument; 
     sf.Visible = false; 
    } 
} 

마지막으로 다음 , 내 문제가있다 곳이다의 StepFinancial 제어

public class StepFinancial : CompositeControl 
{ 
    #region fields 
    private TextBox _argumentTextBox; 
    #endregion 

    #region properties 
    public string Argument { get; set; } 
    #endregion 

    protected override CreateChildControls() 
    { 
     string argument = this.Argument; // this is always null 

     // I have buttons in here (not being displayed) who's events are not wiring up 
     // if I move this into a method, and call the method in Render(), as it seems 
     // to allow me access to the properties there, but I need the value here? 
    } 

    protected override Render(HtmlTextWriter writer) 
    { 
     string argument = this.Argument; // this contains the value of the property set previously 

     this._argumentTextBox.RenderControl(writer); 
    } 
} 

StateBag에 값을 추가하려고했지만 아무 것도하지 않았습니다. CommandStringHanlder에 QueryString을 추가하려고 시도했지만 컬렉션이 잠긴 오류 메시지가 표시됩니다. 캐시와 세션을 시도했는데 (세션이 작동하지 않아 SharePoint에 배포 될 예정 임) 문제가 해결되었습니다. 나는 인터넷 검색, Bing'ing 심지어 야후! 야후! 이것은 행운이지만.

업데이트 나는이 사건의 어떤을 연결하지 않는 한 내가 OnPreRender에서 컬렉션에 컨트롤을 추가 할 수 없습니다 언급하지 못했습니다. EnsureChildControls를 사용하여 응용 프로그램의 다른 부분을 망칠 수도 있습니다. 그러나이 레벨의 속성에서 statebag에 값을 추가 할 수는 있지만, 이것이 매우 나쁜 방법이라고 생각합니다.

답변

0

이 문제를 해결할 수있는 문제는 해결되지 않았지만이 문제를 해결하는 NoSQL 솔루션이 있으며 컨트롤 사이에 값을 저장하고 응용 프로그램을 닫을 때 처분합니다.