I need to iterate trough all dynamically generated text boxes on page when clicking on "Download" button. Following code do not return anything:
protected void Download_Click(object sender, EventArgs e)
{ //???
foreach (Control child in this.form1.Controls)
{
if (child.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox")) //child is somehow never textbox
{
TextBox textBox = (TextBox)child;
System.Diagnostics.Debug.WriteLine(textBox.Text);
}
}
}
I create textBoxes by calling AddTextbox function:
private void AddTextbox(string id, bool isNumber)
{
TextBox textBox = new TextBox();
textBox.ID = id; //set ID
if (isNumber){ textBox.Attributes.Add("type", "number"); }; //if only numbers can be added, html attribute 'type = "number"' is added
form1.Controls.Add(textBox);
form1.Controls.Add(new LiteralControl("<br />")); //just add <br /> html element
}