更新时间:2023-12-06 14:53:04
您重新创建所有你的每一个回发动态控件?
记住每次回发是Page类,你pviously创建需要$ P $显式地重新创建任何控件的新实例。
Remember each postback is a new instance of the Page class and any controls you previously created will need to be explicitly re-created.
更新
如果你不得不在ViewState中添加的项目列表,像这样..
If you had a list of added items in viewstate, something like this..
private List<string> Items
{
get
{
return ViewState["Items"] = (ViewState["Items"] ?? new List<string>());
}
}
然后在你的单击处理程序,你可以简单地添加到这个列表:
Then in your click handler you could simply add to this list :
private void btn_Click(object sender, EventArgs e)
{
this.Items.Add("Another Item");
}
protected overrides CreateChildControls()
{
foreach (string item in this.Items)
{
Passanger p = new Passenger();
p.Something = item;
this.p_passengers.Controls.Add(p);
}
}