If I have a textbox with the name textbox00 how do I get the data from it by using the name?
Asked
Active
Viewed 239 times
-4
-
By using the text property.....textbox00.text – Chris Catignani Oct 15 '20 at 21:50
-
1@ChrisCatignani I assume that `textbox00` is a string, and the OP wants to lookup the object reference based on the control name. Though if the OP isn't using string lookup, then you're absolutely correct. (Text is uppercase though) – gunr2171 Oct 15 '20 at 21:53
-
@gunr2171...Ah...I was using Akum's Razor – Chris Catignani Oct 15 '20 at 21:59
1 Answers
0
You can use Controls.Find() like this:
string ctlToFind = "textbox00";
TextBox tb = Controls.Find(ctlToFind, true).FirstOrDefault() as TextBox;
if (tb != null)
{
Console.WriteLine(tb.Text);
}

Idle_Mind
- 38,363
- 3
- 29
- 40