Get name of textboxcontrol programmatically

  • Thread starter Thread starter Joakim Nilsson
  • Start date Start date
J

Joakim Nilsson

Hi

How do I get the name of a textboxcontrol from within my code.

Say I have a textbox named "txtUser"and want to do this:

string tmp;

foreach (Control control in this.Controls)
{
if (control is TextBox)
{
//here I want to get the name of the textbox...
tmp = control.???????? //this is where I'm stuck!
....
....
}

....
....
}


Is this possible or....?

Thanks.

/Joakim
 
Hi!

You´ll have to explain that the control is not just a Control.
It is in fact a textbox and you do that by a typecast.

tmp = ((textbox)control).Name

Anders
 
...or to be correct - textbox is a System.Windows.Form.TextBox

tmp = ((TextBox)control).Name

Anders
 
Back
Top