Dynamic TextBoxes

G

Guest

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.
 
G

Guest

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>"));
}
}

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
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top