conditional loading of ascx controls.

Discussion in 'ASP .Net Web Controls' started by sameerpande, Jun 9, 2004.

  1. sameerpande

    sameerpande Guest

    Hello friends
    I have 5 ascx controls on a aspx page, and i have to show one control at a time. These all controls are dyanamic and user can traverse from one control to other by some conditions ,but right now my controls gets loaded whenever i come to this page,i want to restict that and want to load each control when it is required
    right now i have implemented the logic for conditional rendering of these controls but in this case all controls gets loaded and initilize the all the required conditions.
     
    sameerpande, Jun 9, 2004
    #1
    1. Advertising

  2. sameerpande

    Jacques Guest

    If I understand you correctly you want to be able to add the user control
    only when certain conditions are met!?

    If that is the case then there is the option to add a placeholder control to
    the page in the position where you intend the contents of the control to
    appear.

    Remove the 5 current controls from the page.

    Wherever it is that you are validating the user input, which should allow
    the next control to become available you could use code such as this to add
    the relevant User Control

    placeHolder1.Controls.Add(Page.LoadControl("../UserControls/myControl.ascx")
    ;

    Hope that helped.

    "sameerpande" <> wrote in message
    news:...
    > Hello friends ,
    > I have 5 ascx controls on a aspx page, and i have to show one control at

    a time. These all controls are dyanamic and user can traverse from one
    control to other by some conditions ,but right now my controls gets loaded
    whenever i come to this page,i want to restict that and want to load each
    control when it is required.
    > right now i have implemented the logic for conditional rendering of these

    controls but in this case all controls gets loaded and initilize the all the
    required conditions.
     
    Jacques, Jun 9, 2004
    #2
    1. Advertising

  3. U should use LoadControl method for this, but if you have postbacks, you
    should be aware of the viewstate problems. You can load the appropriate ASCX
    in the Init phase of the page, but you should ignore ProcessPostBack
    exceptions due to different fields used on different controls. That way your
    controls won't load until you explicitely call LoadControl. One other good
    thing is that your viewstate won't have all items os all controls but only
    those that will dynamicly be loaded. PartialCachingControl will have it's
    instance when put in some container, not before. if you'll have problems
    with setting properties before the control is put inside container.

    --
    RobertK
    { Clever? No just smart. }


    "sameerpande" <> wrote in message
    news:...
    > Hello friends ,
    > I have 5 ascx controls on a aspx page, and i have to show one control at

    a time. These all controls are dyanamic and user can traverse from one
    control to other by some conditions ,but right now my controls gets loaded
    whenever i come to this page,i want to restict that and want to load each
    control when it is required.
    > right now i have implemented the logic for conditional rendering of these

    controls but in this case all controls gets loaded and initilize the all the
    required conditions.
     
    Robert Koritnik, Jun 9, 2004
    #3
    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. Quentin
    Replies:
    1
    Views:
    508
    Quentin
    Jul 29, 2003
  2. Jason Shohet
    Replies:
    1
    Views:
    498
    Kevin Spencer
    Nov 10, 2003
  3. Holger (David) Wagner
    Replies:
    2
    Views:
    1,967
    Holger (David) Wagner
    Jul 3, 2004
  4. Joe
    Replies:
    1
    Views:
    396
    Jeffrey Tan[MSFT]
    Feb 16, 2004
  5. Replies:
    2
    Views:
    553
Loading...

Share This Page