In this blog, we generate a textbox at the runtime. We give the quantity of the textbox that we want to generate in the TextBox. It will generate the textbox.
Step 1:
Open visual studio -> File -> New -> Project -> WindowsFormApplication
Step 2:
Drag panel1, panel2, textBox1 and button from a toolbox window.

Step 3:
Now, Double click on the click me button and write the following code:
try
{
int txtno = int.Parse(txt1.Text);
int pointX = 30;
int pointY = 40;
panel2.Controls.Clear();
for (int i = 0; i < txtno; i++)
{
TextBox a = new TextBox();
a.Text = (i + 1).ToString();
a.Location = new Point(pointX, pointY);
panel2.Controls.Add(a);
panel2.Show();
pointY += 20;
}
}
catch (Exception)
{
MessageBox.Show(e.ToString());
}
Step 4:
Press F5 and run. Enter the no in the textbox, and it will generate the textbox.
For eg: if, here, we enter 4 in the textbox, then it will generate 4 textboxes.


K KrishnaPosted Apr 11, 2021, 6:07 AM
Code for changing and entering new text in text boxes
emma ojPosted Jan 8, 2021, 9:55 PM
Please help me with the code to create Dynamic TextBox in ASP.NET and store data to SQL Server using button click. Every time a user enters x number of textbox inside the Textbox field and click on the button,it will generate the stated x numbers of row with three individual Textbox and another button will save the value to database. Example: x = 4 [ TextBox1 ] [TextBox2] [TextBox3] |New Row| [ TextBox4 ] [TextBox5] [TextBox6] |New Row| [ TextBox7 ] [TextBox6] [TextBox9] |New Row| [ TextBox10 ] [TextBox11] [TextBox12] |New Row| |Save|
Andrew MortonPosted Jul 19, 2018, 11:21 AM
Would the textbox ID's be a1, a2, a3, etc. or would they be textBox1, textBox2, etc.?
Mina LakicPosted Feb 18, 2018, 2:26 PM
Hi, what is txt1.Text here in code?