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?
LVL 1
JigsawTechAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.