getting names of all the textbox on the form

  • Thread starter Thread starter jack
  • Start date Start date
J

jack

Hi,
I m beginner. i wanted to know how to get names of all the textboxes
oded on the form object
Based on that i would then flash the message to the user about the
particular textbox been blank. and fill in the appropriate details.
My guess is that this can be done with foreach(control....
Please help.
 
Jack,

If control is created at design time then you can use for each control
but if it is created at run time then you need to enhance the textbox
class which has name property else you can use position of the textbox
to for the same.

I hope this helps you
 
The controls are placed at design time and just wanted to check which
textboxes are blank. so that names of the textboxex can be taken in a
textboxes and then displayed in a messagebox
Thanks for the replay bhavesh
 
jack said:
I m beginner. i wanted to know how to get names
of all the textboxes oded on the form object

foreach (Control c in this.Controls)
{
if (c is TextBox)
{
MessageBox.Show(c.Name);
}
}

If you want the text boxes to have "real names" (with spaces),
consider storing those names in the Tag property of each text box.

P.
 
Bhavesh said:
If control is created at design time then you can use
for each control but if it is created at run time then
you need to enhance the textbox class

That's not true. You can use a foreach statement to iterate over all
the text boxes that are currently on a form, whether or not they were
created at design time.
else you can use position of the textbox

That would lead to a nasty, unmaintainable project where nobody dared
to resize any controls.

P.
 
i think choosing multipile RequiredFieldValidator's and ValidationSummary
would be more suitable.
 

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