L
learningNET
I am creating a number of textboxes dynamically(depending upon the user
input) and am unable to retrieve that data to store in the DB. When I click
the submit button, the code is unable to find the dynamic textbox by that
name. I am creating the textboxes using a method that gets called after the
user input. Please advise.
I am creating the textboxes using the code below:
private void changeWeight()
{
for( int i=1;i<=int.Parse(txtNum.Text); i++)
{
TextBox txtWt = new TextBox();
txtWt.ID = "txtPWeight"+i.ToString();
Response.Write(txtWt.ID+"<br>");
phWeight.Controls.Add(txtWt);
phWeight.Controls.Add(new LiteralControl("</td></tr><tr><td>"));
}
}
To retrieve data:
private string EnterPositivePlateInfo(int CellNo, int PlateNo)
{
string boxName = "txtPWeight" + PlateNo.ToString();
TextBox tb= phWeight.FindControl(boxName) as TextBox;
if( tb !=null);
else
Response.Write("Does not work "+boxName+"<br>");
return somestring; //returns sql insert statement
}
input) and am unable to retrieve that data to store in the DB. When I click
the submit button, the code is unable to find the dynamic textbox by that
name. I am creating the textboxes using a method that gets called after the
user input. Please advise.
I am creating the textboxes using the code below:
private void changeWeight()
{
for( int i=1;i<=int.Parse(txtNum.Text); i++)
{
TextBox txtWt = new TextBox();
txtWt.ID = "txtPWeight"+i.ToString();
Response.Write(txtWt.ID+"<br>");
phWeight.Controls.Add(txtWt);
phWeight.Controls.Add(new LiteralControl("</td></tr><tr><td>"));
}
}
To retrieve data:
private string EnterPositivePlateInfo(int CellNo, int PlateNo)
{
string boxName = "txtPWeight" + PlateNo.ToString();
TextBox tb= phWeight.FindControl(boxName) as TextBox;
if( tb !=null);
else
Response.Write("Does not work "+boxName+"<br>");
return somestring; //returns sql insert statement
}