0

我的页面上有一个面板:

<asp:Panel ID="pnlTest" runat="server" />

然后我在 Page_Load 上动态添加一个 TextBox:

    TextBox simpleTextBox = new TextBox();
    pnlTest.Controls.Add(simpleTextBox);
    simpleTextBox.ID = "SimpleTextBox-1";

有没有办法在不直接从 Request.Form 中提取的情况下提取在此 TextBox 中键入的信息?我想在我再次添加后我可以做这样的事情:

lblPresentResults.Text = myTextBox.Text;

我知道这个例子似乎是做作的,但我想我会尝试消除我的特定应用程序中的所有其他变量,尤其是在这里提出问题。

4

2 回答 2

3

您需要在加载视图状态之前添加文本框,例如在 Page_Init 中,您应该能够做到这一点。

于 2009-04-06T18:16:57.903 回答
2

只需在InitPreInit而不是 Load 上创建文本框,以便在ViewState 恢复之前它存在于页面中。然后 ASP.Net 将自动为您更新它。

于 2009-04-06T18:16:59.057 回答