Page.Controls - controls are missing?

F

Frank Esser

Hi,

I created an ASP.NET page (test.aspx) with some web controls in GridLayout
(Design time).

When I look at the collection page.controls by

foreach (Control ctrl in Page.Controls)
{
....
}

then I can not see all the controls on the page.

Is there a special controls collection for the design time gridlayout
controls?

Best regards
Frank
(newbie)
 
E

Eliyahu Goldin

Frank,

Every Control collection contains only immediate children.

Eliyahu
 
F

Frank Esser

Hallo Eliyahu ,

thanks for your answer.

How can I iterate through the controls that were created at design time?
For example when I want to make all available controls invisible or disabled
at runtime?
At the moment I have to call them directly by name. This is very ugly for my
coding...

Thanks
Frank
 
E

Eliyahu Goldin

I must confess that in similar situations I do operate on controls
individually. Just to add a few extra lines of code is often a better idea
than spending hours on looking for more elegant solutions. If you don't want
this, you can either navigate Controls collections or try find a sort of
container element (a panel?) that would disable its children when it is
disabled.

Eliyahu
 
F

Frank Esser

But if I want to write a global function that makes all controls on a web
page invisible for example then I have to use a generic way of accessing the
page controls...

I can not imagine that there is no way to do that in the .NET framework or
ASP.NET.
That would really be a strange mistake by Microsoft...

Other opinions?
 
G

Guest

Hi Frank,

you can iterate through all controls in your page after the Init-Event was
executed. In case you want to set all sub-control unvisible do the following:

public class MyControl : System.Web.UI.Control /* or any other base-class
e.g. System.Web.UI.WebControls.WebControl */

...

void setVisibility(bool visible)
{
foreach (Control ctl in this.Controls)
{
ctl.Visible = visible;
}
}

...

}

Hope that helps
patrick
 
E

Eliyahu Goldin

This will affect only direct children. You need to implement recursion to go
all the way down.

Eliyahu
 
E

Eliyahu Goldin

That's nice. I've got thanks for an article written by Steve.

That's an ideal example how newsgroup should work.

Question > Directions > Research > Answer.

Eliyahu
 
G

Guest

Hi Eliyahu,

in case of visibility you do NOT have to implement recursion. When the
parent is not visible childcontrols are displayed neither.

Or am I wrong?
patrick
 
E

Eliyahu Goldin

Very likely, don't remember if I had it somewhere in my applications.

Eliyahu
 

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
473,770
Messages
2,569,584
Members
45,078
Latest member
MakersCBDBlood

Latest Threads

Top