• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2847
  • Last Modified:

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?
0
JigsawTech
Asked:
JigsawTech
  • 2
1 Solution
 
Juan_BarreraCommented:
Hi, you can load the UserControls dynamically on ActiveViewChanged.
Here is an example. you need to tweak it to suit your scenario:



   Protected Sub MultiView1_ActiveViewChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MultiView1.ActiveViewChanged
        Dim uc As UserControl
        Select Case MultiView1.ActiveViewIndex
            Case 0
                uc = LoadControl("/UserControlForView0Path")
            Case Else
                uc = LoadControl("/UserControlForView1Path")
        End Select
        MultiView1.Views(MultiView1.ActiveViewIndex).Controls.Add(uc)
    End Sub

Open in new window

0
 
JigsawTechAuthor Commented:
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?
0
 
Juan_BarreraCommented:
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

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now