saving dynamically created textbox values using "for loop"

Dec 17 2014 2:32 AM
hi,

I have created a dynamic textbox using "for loop".i am unable to retrive the data from dynamically created textbox using for loop.Please find the code below to create dynamically created textbox and to retrive data.Please help to solve the problem.

Used ajax to stop the fullpage postback.
//Generate textbox
protected void button1_click(object sender,EventArgs e)
{
int count=Convert.ToInt32(txtbox.Text);
for(int i=0;i<count;i++)
{
 TextBox tb=new TextBox();
tb.ID="txtser"+i.ToString();
panel1.Controls.Add(tb);
}
}

// Retrive value

protected void button2_click(object sender,EventArgs e)
{
int c=Convert.ToInt32(txtbox.Text);
for(int j=0;j<c;j++)
{
 TextBox t=(TextBox)(panel1.FindConrols("txtser"+i.ToString()));
 Label1.Text=t.Text;
}
}


Answers (6)