I have a web page where I have dropdownlist box with autopostback set
to true. The box has 3 items: 1, 2, and 3. I also have a Placeholder
and a button. Each time the user change the value of the
dropdownlist, I create dynamically one or x text box. Here is my
code...
for (int i = 0; i < Convert.ToInt32(ddListsRpt.SelectedValue); i++)
{
TextBox txtbx = new TextBox();
txtbx.Visible = true;
this.Placeholder3.Controls.Add(new LiteralControl("test: "));
Placeholder3.Controls.Add(txtbx);
}
The user can enter any value in each created text box.
Here is the code for my button:
foreach (Control ctrl in PlaceHolder3.Controls)
{
if (ctrl.ToString() == "System.Web.UI.WebControls.TextBox")
{
Response.Write (((TextBox) ctrl).Text.ToString());
}
}
What is interesting is that, for instance, a text box is dynamically
created then I enter 123 and click on the button. On the postback,
the text box disappear but I want it to stay so I can display the
value of the text box. Can someone tell me why it disappear? Thanks.