A
Andrew
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
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.
-- Andrew