Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Controls / September 2004

Tip: Looking for answers? Try searching our database.

Iterating through Controls Question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrew - 28 Sep 2004 20:00 GMT
Hey all,

   I am still getting the hang of .Net so I'm posting this question looking
for someone to maybe explain the following process to me so I can better
understand just what is going on here.
   I have an aspx page with a few Panel Web Controls on it.  I turn them on
and off depending on what the user is doing.  I wanted to make the code a
little shorter on the back end by writing a subroutine that turns off all
panels by iterating through the controls collection:

   My first attempt didn't go so well:
           For Each p As Panel In Me.Controls
               p.Visible = False
           Next

   After some searching on Google, CodeProject, and the MSDN help files, I
was able to correct the function so it worked:
           For Each c As Control In Me.Controls.Item(1).Controls
               If TypeOf c Is Panel Then
                   c.Visible = False
               End If
           Next

   My question is in two parts: 1 - Obviously, why did the first one not
work, and 2 - Why do I need to use "Me.Controls.Item(1).Controls" to access
the controls collection for the page?

   Again, I am still getting a handle on all this, so I appreciate any
replies to be as simple and straight forward as possible. :)  Thanks!

-- Andrew
Alvin Bruney [MVP] - 29 Sep 2004 00:47 GMT
i could explain but the easier way to understand it is to step thru loop 1
and 2 with the debugger
paying attention to what is returned. then you can use the watch window to
see how the control
container is setup. that way you will understand what is going on internally
as opposed to reading
fluffy stuff. its the best way to learn.

Signature

Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok

> Hey all,
>
[quoted text clipped - 30 lines]
>
> -- Andrew
Andrew - 29 Sep 2004 18:47 GMT
Alvin,

I appreciate the time and effort of your response and thank you, but I have
the thing working just fine and using the debugger was part of how I managed
that.  With this application, I have the "what", I am attempting to
understand the "why".  Not harping on you, but sometimes, I really am after
the answer to the question I asked.  I just have to leave it up to those out
here to read the question as I wrote it.

-- Andrew

> i could explain but the easier way to understand it is to step thru loop 1
> and 2 with the debugger
[quoted text clipped - 38 lines]
> >
> > -- Andrew
Alvin Bruney [MVP] - 29 Sep 2004 19:36 GMT
roughly
a panel is unique in its ability to house other controls in a collection.
when you iterated the panel in the first loop, you returned references to
the controls
collections. your second loop probes the collection of controls and returns
the first control from the collection which is off type panel. loop 1 can be
made to work
by refining the returned results by the way.

hth

Signature

Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok

> Alvin,
>
[quoted text clipped - 63 lines]
>> >
>> > -- Andrew

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.