我使用下面的代码将动态数量的文本框添加到 div,但在回发消失之前我无法访问它们。我希望能够循环它们以获取值,但无论我如何尝试,我都无法获取这些框,因为当我单击按钮时它们都消失了。我该怎么做呢?
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++;
}