If you want the controls to stick, you need to add them in the Init handler event
Main Topics
Browse All TopicsI have a web application in which I won't know the number of fields I need until runtime. Say I'm reading a form structure from a database which will tell me all of the fields i need to generate. I then loop through that collection and add a label and a text box. It may be 3 or 30 controls I need to add. I'm looking the page you sent, but I'm not sure how it applies.
The controls are correctly generated for the user, but on post back they simply don't exist. I tried looping through the controls in my panel, but it shows zero on postback. I tried looping through the entire page, but couldn't find any TextBox controls.
I read somewhere that seemed to imply that I need to recreate the controls on postback and ASP.NET would take care of settings values that the user entered.
I tried this, but the values don't get set.
If I run this code on postback, there are no Textbox on the page
private void LoopThroughControls(Contro
{
foreach (Control frmCtrl in control.Controls)
{
Response.Write(frmCtrl.Get
Response.Write("<br />");
if (frmCtrl.GetType().ToStrin
RunTimeParams.Add(frmCtrl.
if (frmCtrl.HasControls() == true)
LoopThroughControls(frmCtr
}
}
Here's the code I'm using to create the controls.
foreach(...)
{
Label FieldLabel = new Label();
FieldLabel.Text = FieldFromDB;
TextBox FieldTextBox = new TextBox();
RuntimeParamTextBox.ID = "DBField" + i;
TableRow InputTableRow = new TableRow();
TableCell InputTableCellLabel = new TableCell();
ParamInputTableCellLabel.C
TableCell ParamInputTableCellText = new TableCell();
ParamInputTableCellText.Co
ParamInputTableRow.Control
ParamInputTableRow.Control
ParamInputTable.Controls.A
}
RunTimeParamsPanel.Control
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
>> How To Get Access To Controls That You Add Programmatically on Postback
Answer: recreate them on every postback and assign with the same ID.
Find a working code sample here.
http://www.experts-exchang
Business Accounts
Answer for Membership
by: Infinite_RecursionPosted on 2005-11-11 at 13:12:33ID: 15276946
where do u have this code in Page_Load?