it will work in asp.net
public partial class _Default : System.Web.UI.Page
{
public List<TextBox> ListOfTextBoxes = new List<TextBox>();
protected void Page_Load(object sender, EventArgs e)
{
FindTextBoxes(Page, ListOfTextBoxes);
}
private void FindTextBoxes(Control Parent, List<TextBox> ListOfTextBoxes)
{
foreach (Control c in Parent.Controls) {
if (c.HasControls())
{
FindTextBoxes(c, ListOfTextBoxes);
}
else {
if (c is TextBox)
{
ListOfTextBoxes.Add(c as TextBox);
}
}
}
}
}