Dynamic TextBox on LinkButton click
Posted
by
Alex Peta
on Stack Overflow
See other posts from Stack Overflow
or by Alex Peta
Published on 2011-01-07T20:41:03Z
Indexed on
2011/01/07
20:54 UTC
Read the original article
Hit count: 252
I am creating dynamic TextBoxes in a page by clicking a LinkButton.
However, after that, if the page is submitted, I can't find the items created dynamically, thus, can't send the information to the database.
protected void lbAddTag_Click(object sender, EventArgs e)
{
for (int i = 0; i < 3;i++ )
{
CreateTextBox("txtTag-" + i.ToString());
}
}
private void CreateTextBox(string ID)
{
TextBox txt = new TextBox();
txt.ID = ID;
txt.Width = Unit.Pixel(300);
//txt.TextChanged += new EventHandler(OnTextChanged);
txt.AutoPostBack = false;
tagsPanel.Controls.Add(txt);
Literal lt = new Literal();
lt.Text = "<br /><br />";
tagsPanel.Controls.Add(lt);
}
If I put:
foreach (Control c in tagsPanel.Controls)
{
if (c is TextBox)
{
lblError.Text += c.ClientID + " , ";
}
}
in the lbAddTag_Click method I can see the items, and they exist, but if I submit the page and try to insert the values in the database nothing...
Any hint is much appreciated.
© Stack Overflow or respective owner