How to stop a web control from loading child controls?

a 夏天 提交于 2019-12-11 17:43:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!