Assign an attribute to all my web controls

D

Diego

Hi,
I want assing an attribute to all my web controls, i thought with
Page.Controls property but i don´t know how that works.
How can i iterate Page.Controls and set an attribute like Enable=false in
all my web controls?????
 
J

JezB

You have to parse the Controls collection of your Page object, but bear in
mind that some controls have their own Controls collection for sub-items so
your routine has to be recursive.
 
J

JezB

Something like :

private void ParseControls (Control c)
{
// do something to the control, (but not the whole Page?)
if (!(c is Page)) c.Enabled = false;

// Now loop through any child controls (but not for populated datagrids)
if (c.HasControls())
{
foreach (Control ch in c.Controls)
{
ParseControls(ch);
}
}
}

then just call it and pass it your Page.
 

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

Members online

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,083
Members
48,773
Latest member
Kaybee

Latest Threads

Top