Dynamic TextBox

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
}
 
L

learningNET

I found the solution on one of the other threads (Answer by: William F.
Robertson, Jr.). The trick was to use:
string s = Request.Form["txtPWeight" + PlateNo.ToString()];
It saved the textbox value in variable s.
 

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

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top