问题
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
回答1:
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
来源:https://stackoverflow.com/questions/1396185/how-to-stop-a-web-control-from-loading-child-controls