Groups | Blog | Home
all groups > c# > october 2005 >

c# : getting names of all the textbox on the form


jack
10/20/2005 10:08:01 PM
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.
Bhavesh
10/20/2005 10:17:03 PM
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





[quoted text, click to view]
jack
10/20/2005 10:31:23 PM
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
10/20/2005 11:55:01 PM
Thanks guys got it
Paul E Collins
10/21/2005 5:52:08 AM
[quoted text, click to view]

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.

Paul E Collins
10/21/2005 5:52:25 AM
[quoted text, click to view]

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.

[quoted text, click to view]

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

P.

The Crow
10/21/2005 9:07:45 AM
i think choosing multipile RequiredFieldValidator's and ValidationSummary
would be more suitable.

AddThis Social Bookmark Button