I use the code below to add a dynamic amount of textboxes to a div but I can’t get to them before dissappaering at postback. I’d like to be able to loop them to get the values but no matter how I try I can’t get the boxes since they all disappear as I click the button to do so. How do I go about to do this?
foreach (string month in budget.PeriodMonths)
{
TableRow tr = new TableRow();
TableCell tc1 = new TableCell();
TableCell tc2 = new TableCell();
tc1.HorizontalAlign = HorizontalAlign.Right;
Label monthName = new Label();
monthName.Text = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(month);
tc1.Controls.Add(monthName);
TextBox monthInput = new TextBox();
monthInput.ID = "month_" + i.ToString();
monthInput.Attributes.Add("onkeypress", "return isNumberKey(event)");
monthInput.Width = 50;
monthInput.Style.Add("TEXT-ALIGN", "RIGHT");
if (i < sellerBudget.PeriodValues.Length)
monthInput.Text = sellerBudget.PeriodValues[i].ToString();
else
monthInput.Text = "0";
tc2.Controls.Add(monthInput);
tr.Cells.Add(tc1);
tr.Cells.Add(tc2);
bpTable.Controls.Add(tr);
i++;
}
This one helped me out enormously! http://techbrij.com/197/retrieve-value-of-dynamic-controls-in-asp-net