views:

245

answers:

1

This is for ASP.NET. Think about the multiview control. It has 1 to many view controls. Each view control has the ability of holding controls, but, yet, only one view is visible at a time.

Keeping that in mind, I'm thinking I want to "tell" the non-visible views to NOT LOAD, therefore, NOT LOADING the child controls.

In my sample, during the view's load, I check to see if it is the active view. If it is not active, then I stop processing the load. Unfortunately, views that are not active still have their load event run and all the controls in the control tree run their load.

Back to the question: Is there a way to stop the child controls from running for the view that is not active?

Code Sample:

Private Sub viewDisplayArticle_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles viewDisplayArticle.Load

  If Not mvwHealthArticles.ActiveViewIndex = mvwHealthArticlesView.DisplayArticle Then Exit Sub

  callSomeKillerMethod()

End Sub
A: 

Set the non visible child control's Visible property to False, and then only run the Load event handler in the child controls when Visible is true.

Private Sub viewDisplayArticle_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles viewDisplayArticle.Load

  If Visble = True
  Then ' Load Logic
  Else ' do nothing

End Sub
jrummell
Good idea, but that is not permitted when dealing specifically with System.Web.UI.WebControls.View.System.InvalidOperationException: The Visible property of a View control can only be set by setting the active View of a MultiView.
MADCookie
That's interesting. I would probably try to make a templated control (like a GridView with <EditTemplate>, <ItemTemplate>, etc) as I've never tried a MultiView control ... good luck!
jrummell