You can use the FindControl method of the Page class.
This method takes a parameter, which is the TextBox identifier that you must set when creating:
txtbx.ID = "txtbx1";
Then you can select it:
TextBox txtbx1 = (TextBox)FindControl("txtbx1");
and use it.
Edit: Since the initial question added that it refers to Windows Forms, my answer above is off topic.
On Windows Forms, you should simply use a member variable of the class instead of a local variable. For instance:.
public partial class MyForm { ... private TextBox txtbx; ... private void createControls() { txtbx = new TextBox(); txtbx.Text = ""; txtbx.Name = "txtbx1"; txtbx.Location = new Point(10, 10); txtbx.Height = 20; txtbx.Width = 50; Controls.Add(txtbx); } private void someOtherFunction() {
source share