This is not exact code, only a sample. will help you how to find controls and save to database. here am just printing
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class dynamicButton : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
for (int i = 0; i < 10; i++)
{
TextBox txt = new TextBox();
txt.ID = "genTxt" + i.ToString();
PlaceHolder1.Controls.Add(txt);
}
}
else
{
for (int i = 0; i < 10; i++)
{
if (PlaceHolder1.FindControl("genTxt" + i.ToString()) == null)
{
TextBox txt = new TextBox();
txt.ID = "genTxt" + i.ToString();
PlaceHolder1.Controls.Add(txt);
}
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
System.Collections.Hashtable hastTab = new System.Collections.Hashtable();
for (int i = 0; i < 10; i++)
{
string txtID = "genTxt" + i.ToString();
if (PlaceHolder1.FindControl(txtID) != null)
{
TextBox txt = (TextBox)PlaceHolder1.FindControl(txtID);
if (txt != null)
{
hastTab.Add(txt.ID, txt.Text);
}
}
}
System.Collections.IDictionaryEnumerator IdEnum = hastTab.GetEnumerator();
while (IdEnum.MoveNext())
{
Response.Write(IdEnum.Key.ToString() + "," + IdEnum.Value.ToString()+"</br>");
}
}
}
<pre lang="xml"><%@ Page Language="C#" AutoEventWireup="true" CodeFile="dynamicButton.aspx.cs" Inherits="dynamicButton" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</div>
</form>
</body>
</html>