获取回发前输入的TextBox值

时间:2012-08-06 12:34:51

标签: postback

我使用下面的代码向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++;
    }

1 个答案:

答案 0 :(得分:0)