|
发表于 2020-6-25 10:00:01
|
显示全部楼层
private int ControlsCount
{
get
{
return ViewState["ControlsCount"] == null?0:(int)ViewState["ControlsCount"];
}
set
{
ViewState["ControlsCount"] = value;
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
UserControl c = (UserControl) this.LoadControl("MyControls.ascx");
this.Panel1.Controls.Add(c);
this.ControlsCount ++;
}
private void Button2_Click(object sender, System.EventArgs e)
{
if(this.Panel1.Controls.Count >0)
{
this.Panel1.Controls.RemoveAt(this.Panel1.Controls.Count-1);
this.ControlsCount --;
}
}
private void Page_Load(object sender, System.EventArgs e)
{
for(int i=0;i<this.ControlsCount;i++)
{
UserControl c = (UserControl) this.LoadControl("MyControls.ascx");
this.Panel1.Controls.Add(c);
}
}
|
|