Iterate through all panels on webform?

Discussion in 'ASP .Net' started by Rob Meade, Jan 16, 2007.

  1. Rob Meade

    Rob Meade Guest

    Hi all,

    I have a page, where, because it had to all be in one page there are a
    multitude of panels, with the use of a handful of conditions and the ability
    to show/hide panels I am able to make this page look like the user is moving
    between many...

    Here's my problem...

    I started off by simply seting the visibility to true/false etc in each code
    block where I needed to turn them on or off - as I got more this was getting
    painful, so I then created a sub, and for each panel passed in a true/false
    value as a parameter...

    For example

    Private Sub ShowPanels(byval panel1 as boolean, byval panel2 as boolean,
    byval panel3 as boolean)

    panel1.visible = panel1
    panel2.visible = panel2
    panel3.visible = panel3

    End Sub

    *note, they are not named like that - its just an example!

    This was working fine to start with but as I've grown the number of panels,
    the parameters being passed in are getting quite big, and of course each
    time I add one I have to go back through my code where I have the sub called
    and update it- its getting to be a pain in my roses red....

    So, what I'm looking for is something a bit clever...

    What I was thinking was perhaps a sub which would iterate through a
    collection of controls on the page, looking for just the "panels", once it
    has all of those, set them all to visible = false apart from the ones I want
    to show which would be specified in the parameters...

    However, I can see some problems with this...

    1. I have no idea how to iterate through the controls on the page just
    looking for the panels...
    2. Sometimes I need to show 1 panel, sometimes 2, something 4, so how can i
    have a varying length list of parameters going in, ie, ShowPanels(panel1,
    panel2, panel8) or ShowPanels(panel4, panel5)

    Any help with this would be appreciated...

    Its probably not the best of approaches, and I'm sure with .net 2 there are
    many more clever ways of doing what I need to do - however I dont, currently
    in this project have the luxury of time to learn too many new things - so
    figured I'd go with something easier...

    Thanks in advance for your time.

    Regards

    Rob
     
    Rob Meade, Jan 16, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fabian

    Iterate through Panels

    Fabian, Oct 4, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,892
    Matt Berther
    Oct 4, 2004
  2. Gogo
    Replies:
    1
    Views:
    2,122
    Sudsy
    Sep 4, 2003
  3. runescience
    Replies:
    0
    Views:
    1,478
    runescience
    Feb 9, 2006
  4. jaso
    Replies:
    5
    Views:
    722
    Richard Heathfield
    Jun 11, 2006
  5. John
    Replies:
    4
    Views:
    936
    RedGrittyBrick
    Apr 1, 2008
Loading...

Share This Page