Link to home
Start Free TrialLog in
Avatar of JigsawTech
JigsawTech

asked on

Dynamic Load Usercontrols with MultiView

Hi Folks,

At present I have a Multiview attached to a menu control. So when I click button1, view1 is shown.
When I click button2, view2 is shown etc - pretty basic.

In each "view", I have a user control.

The problems is; when click button1, all other views are loaded, and hence their usercontrols are loaded.

This is slow.

I want to LOAD view1 and only have the contents of view1 loaded (etc the usercontrol in view1)

Any tips on how to achieve this?
ASKER CERTIFIED SOLUTION
Avatar of Juan_Barrera
Juan_Barrera
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JigsawTech
JigsawTech

ASKER

Hi Juan_Barrera,

Thanks for that.

Just one more thing - some of the controls I'm loading within the multiview have postbacks .. and when I do the form just dispears! Its like the control just unloads.

What can I do?
You need to load the control on every postback then. If you only do it on MultiView1_ActiveViewChanged, it will only load when a view changes.
How to solve this? Well, you have many ways. I think that the easiest would be to check the ActiveView on PageLoad and call a procedure similar to the other one (you can even encapsulate both in just one method)
 

'onPageLoad: 
 
        Dim uc As UserControl
        If Not MultiView1.ActiveViewIndex = -1
        Select Case MultiView1.ActiveViewIndex
            Case 0
                uc = LoadControl("/UserControlForView0Path")
                cuc = "/UserControlForView0Path"
            Case Else
                uc = LoadControl("/UserControlForView1Path")
                cuc = "/UserControlForView1Path"
        End Select
        MultiView1.Views(MultiView1.ActiveViewIndex).Controls.Add(uc)

Open in new window