I was faced with the problem in one of my Web projects of retrieving the value of the dynamically created TextBox.
I am submitting the small snippet here that might be useful for someone.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication6
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TextBox new_textbox = new TextBox();
new_textbox.ID = "txt" + 1;
new_textbox.Text = "";
PlaceHolder1.Controls.Add(new_textbox);
}
protected void Button1_Click(object sender, EventArgs e)
{
string OptionID = "txt" + 1;
TextBox tb = (TextBox)PlaceHolder1.FindControl(OptionID);
Response.Write(tb.Text);
}
}
}
Creating Dynamic TextBox and Get Its Value
This code snippet shows how to create a Dynamic TextBox and get its value in the code in Windows Forms.

Kumar SambhaveditedPosted May 16, 2013, 11:23 PM EDTEdited May 17, 2013, 12:38 AM EDT
Please check this codding is working properly in Windows Application ************************************************* using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Diagnostics; namespace DynamicTexBox { public partial class Form2 : Form { public Form2() { InitializeComponent(); } TextBox[] textBoxes; private void button1_Click(object sender, EventArgs e) { int value = 3; textBoxes = new TextBox[value]; for (int i = 1; i < value; i++) { textBoxes[i] = new TextBox(); textBoxes[i].SetBounds(30, i * 30, 60, 20); this.Controls.Add(textBoxes[i]); } } private void button2_Click(object sender, EventArgs e) { int myTotal = 0; foreach (Control ctl in this.Controls) { if (ctl.GetType() == typeof(TextBox)) { myTotal += Convert.ToInt32(ctl.Text); } } label1.Text = myTotal.ToString(); } } }
Gihan PereraPosted Jan 2, 2011, 9:38 PM EST
i need get value from dynamic created textbox in windows forms(not web forms).