[英]passing values between composite controls
我有一个控件:定义一个按钮的复合控件。 在使控件可见之前,该按钮调用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中,什么也没有。 我尝试在CommandEventHanlder中添加QueryString,但得到一个集合被锁定的错误消息。 我尝试了缓存和会话(会话将无法工作,因为它将被部署到SharePoint),所以这是不可能的。 我尝试了谷歌搜索,甚至还对Yahoo! 这可是没有运气。
更新我没有提到,我无法将控件添加到OnPreRender下的集合中,因为它不会连接任何事件。 我不能使用确保孩子控制,因为它会弄乱应用程序的其他部分。 但是,我可以将这个级别的属性的值添加到状态包中,但是我觉得这样做是非常糟糕的方法。
我并没有真正解决此问题,但是我有一个NoSQL解决方案作为基础,并在其中存储了控件之间的值,并在应用程序关闭时进行处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.