如何将PostBack数据提取到动态添加的UserControl(.NET)中? [英] How to pull PostBack data into a dynamically added UserControl (.NET)?
问题描述
我的页面上有一个面板:
I have a Panel on my Page:
<asp:Panel ID="pnlTest" runat="server" />
然后我在Page_Load上向其动态添加一个文本框:
Then I dynamically add a TextBox to it on Page_Load:
TextBox simpleTextBox = new TextBox();
pnlTest.Controls.Add(simpleTextBox);
simpleTextBox.ID = "SimpleTextBox-1";
是否有一种方法可以提取此TextBox中键入的信息,而不必直接从Request.Form中提取它?再次添加后,我以为可以做以下事情:
Is there a way to pull in the information typed in this TextBox without pulling it directly from Request.Form? I thought I could do something like this after I added it again:
lblPresentResults.Text = myTextBox.Text;
我知道这个示例似乎是人为的,但是我认为我会尝试消除特定应用程序中的所有其他变量,尤其是在这里问一个问题.
I know this example seems contrived, but I figured I'd try to eliminate all the other variables in my specific application, especially to ask a question here.
推荐答案
您需要在加载视图状态之前(例如在Page_Init中)添加文本框,并且您应该能够做到这一点.
You need to add the textbox before viewstate loads, such as in Page_Init, and you should be able to do this.
这篇关于如何将PostBack数据提取到动态添加的UserControl(.NET)中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!