-3

I create class, in which I need to find TextBox by name. Im using this, but here there is a problem, that FindName doesn't exisst in namespace.

object component = this.FindName(componentName);  
TextBox child = component as TextBox;    

Can I use FindName method in class?

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
Crooker
  • 465
  • 3
  • 6
  • 16
  • 4
    What on earth are you trying to do, again? What do you expect FindName to do? – SimpleVar Jun 03 '12 at 11:17
  • I have some TextBoxes and I need edit one of them by name. [link](http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.findname.aspx) – Crooker Jun 03 '12 at 11:19
  • And when you say name, you mean variable name? And are the textboxes in a form that the code is in scope of? – SimpleVar Jun 03 '12 at 11:21
  • 1
    @Crooker, if you're using Windows Forms, see [this question](http://stackoverflow.com/questions/3898588/find-control-by-name-from-windows-forms-controls). If you're using ASP.NET Web Forms, see [FindControl()](http://msdn.microsoft.com/en-us/library/486wc64h.aspx). – Frédéric Hamidi Jun 03 '12 at 11:21
  • Yes, variable. Yey, they are. – Crooker Jun 03 '12 at 11:24
  • What are you using? Winforms? WPF? ASP.NET? Something else? – svick Jun 03 '12 at 11:25

1 Answers1

1

You should use this.FindControl (`this' is optional of course).

Ofer Zelig
  • 17,068
  • 9
  • 59
  • 93
  • Still the same problem. Could be a problem with namespace im using? I think namespaces like System.Windows;? – Crooker Jun 03 '12 at 11:43
  • I'm not sure about WPF. Have a look at this: http://stackoverflow.com/questions/636383/wpf-ways-to-find-controls – Ofer Zelig Jun 03 '12 at 13:38