Panels and dynamic controls...again

Discussion in 'ASP .Net Web Controls' started by PZ, Jan 12, 2009.

  1. PZ

    PZ Guest

    Sorry for posting again, been away for a while, just need to refresh this
    issue.

    I have a page on which I have 2 panels. Each panel has a DropDownList
    control which is generated dynamically at init. The first panel (panel1) is
    visible, while the other panel (panel2) is currently not visible.

    Just wondering if there is a way around wasting time on creating the
    controls for panel2, when it is not shown yet? I only want to create it when
    panel2 becomes visible, but then I get into the classic page cycle problem,
    where events and viewstates makes it impossible to keep values to the
    dropdownlist dynamic.

    Above is the simple solution. After some weeks of development, I have more
    like 11 panels with alot of controls on each of them. Some dynamic, some
    hardcoded items. I'm using viewstate and OnPrerender event to determine if a
    panel should be visible. It works fine, but getting kind of slow when you
    need to generate ALL controls and bind data at each cycle. If you need to
    show one panel with one control, it's kind of frustrating that I need to
    create 100+ controls before I can display that one control.

    My goal is to keep everything on one aspx page, but not sure if this is the
    right strategy if you have a rather large site with many functions and
    controls.

    Please advise.

    There must be a better way to design this?
     
    PZ, Jan 12, 2009
    #1
    1. Advertisements

  2. One thing you could try is making each Panel into a UserControl (*.ascx) and
    then setting the Visible property of that UserControl. You may also be able
    to use the IsPostBack property in several places to help prevent unnecessary
    renderings. I haven't done any testing on either of these, but they may
    help. I wasn't quite sure from your posting, but if you are never showing
    more than one Panel at a time, you may want to look into the MultiView
    control. Even if it doesn't make your code more efficient as far as
    rendering more controls than you will be displaying (maybe it does, I
    haven't checked), it will definitely make your code more organized if you
    are only displaying one at a time. I can't promise whether any of this will
    help, but maybe they will give you some ideas. Good Luck!
     
    Nathan Sokalski, Jan 15, 2009
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.