0

Is there a way to get a control by name by using a combined name (just like a messagebox: MessageBox.Show("hi 1 " + lbltext.Text + " hi 2.");)? For example I am using a label that has the name lblName, I want to use a tag of a button: button.Tag = "Name";

I tried simular things like this, but I could not get it to work:

lbl+"(string)button.Tag".Visible = true;
Gekkehond
  • 128
  • 1
  • 13

2 Answers2

1

Try this:

formName.Controls.Find("lbl" + button.Tag.ToString(), true).FirstOrDefault()
lyrqs
  • 78
  • 1
  • 8
0

you can do:

((TextBox)Controls["tb1"]).Text = "hey";

the tb1 can be anything, i mean however you chose to compose it, but it should, of course, exist in the control collection.

user734028
  • 1,021
  • 1
  • 9
  • 21