int LoadedTimes
{
get
{
object o = ViewState["LoadedTimes"];
if (o == null)
return 0;
return (int)o;
}
set
{
ViewState["LoadedTimes"] = value;
}
}
void CreateControls()
{
for (int i=0; i < LoadedTimes; i++)
{
Control c = LoadControl("YourUserControl.ascx");
c.ID = "UC" + i.ToString();
ph.Controls.Add(c);
}
}
void Page_Load(...)
{
CreateControls();
}
void Button_Click(...)
{
Control c = LoadControl("YourUserControl.ascx");
c.ID = "UC" + LoadedTimes.ToString();
ph.Controls.Add(c);
LoadedTimes++;
}
void GetValueButton_Click(..)
{
for (int i=0; i < LoadedTimes; i++)
{
YourControl uc = (YourControl)ph.FindControl(""UC" + i.ToString();");
//get the text from your user control
}
}