This might give you an idea:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
</head>
<body>
<form id="form1" runat="server">
<asp:Panel ID="Panel1" runat="server" EnableViewState="False" ViewStateMode="Disabled">
</asp:Panel>
<asp:button id="Button_AddControl" runat="server" text="Add Control"
onclick="Button_AddControl_Click" />
<asp:Button ID="Button_Save" runat="server" onclick="Button_Save_Click"
Text="Save" />
</form>
</body>
</html>
Code behind:
public partial class WebForm1 : System.Web.UI.Page
{
List<string> lstData
{
get
{
if (ViewState["lstData"] == null)
ViewState["lstData"] = new List<string>();
return (List<string>)ViewState["lstData"];
}
set
{
ViewState["lstData"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
LoadControl();
}
}
void LoadControl()
{
for (int i = Panel1.Controls.Count; i < lstData.Count; i++)
{
Panel p = new Panel();
TextBox textBox = new TextBox();
p.Controls.Add(textBox);
Panel1.Controls.Add(p);
}
}
void LoadData()
{
for (int i = 0; i < lstData.Count; i++)
{
((TextBox)Panel1.Controls[i].Controls[0]).Text = lstData[i];
}
}
void SaveData()
{
for (int i = 0; i < lstData.Count; i++)
{
lstData[i] = ((TextBox)Panel1.Controls[i].Controls[0]).Text;
}
}
protected void Button_Save_Click(object sender, EventArgs e)
{
SaveData();
}
protected void Button_AddControl_Click(object sender, EventArgs e)
{
lstData.AddRange(new string[3]);
LoadControl();
LoadData();
}
}