T...">

How to transfer PostBack data to dynamically added UserControl (.NET)?

I have a panel on my page:

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

Then I dynamically add a TextBox to it on the_Load page:

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

Is there a way to extract the information entered into this TextBox without pulling it directly from Request.Form? I thought I could do something like this after adding it again:

 lblPresentResults.Text = myTextBox.Text; 

I know this example seems far-fetched, but I decided that I would try to eliminate all other variables in my particular application, especially to ask a question here.

0
source share
2 answers

You need to add a text box before loading in the view, for example, in Page_Init, and you must do this.

+3
source

Just create a text field on Init or PreInit , not Load, so that it exists on the page before restoring ViewState. Then ASP.Net will automatically update it for you.

+2
source

All Articles