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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top