how to retrieve contents from dynamically created textboxes
hello im creating textboxes and their number depends on the contents of a dropdownlist.
Code:
protected void dropDownList_SelectedIndexChanged(object sender,EventArgs e)
{
int number=int.parse(dropdownitem.Text);
for(int i=0;i<number;i++)
{
TextBox tb=new TextBox();
tb.ID="tb"+i.ToString();
Panel1.Controls.Add(tb); //placing the textboxes on a panel
}
}
now i want to retrieve the data from these textboxes. but my approach is not clear
Code:
protected void button1_Click(object sender,Eventargs e)
{
for(int i=0;i<Request.Form.Count;i++)
{
string strid="tb"+i.ToString();
string value=Request.Form[strid].ToString();
}
}
this is definitely not working.can you suggest something that serves my purpose? thanks in advance
Re: how to retrieve contents from dynamically created textboxes
You need to locate and init the control before you can use it
PS.. I'm a vb guy so this may not work right of the bat...
Code:
protected void button1_Click(object sender,Eventargs e)
{
for(int i=0;i<Request.Form.Count;i++)
{
string strid="tb"+i.ToString();
control txtboxinput = Panel1.FindControl(strid);
string value=txtboxinput.Text.ToString();
}
}