如何阻止 Web 控件加载子控件?
这是针对 ASP.NET 的。考虑一下多视图控制。它有一对多视图控件。每个视图控件都具有保持控件的能力,但是一次只有一个视图可见。
记住这一点,我想我想“告诉”不可见视图不加载,因此不加载子控件。
在我的示例中,在视图加载期间,我检查它是否是活动视图。如果它不活动,那么我将停止处理负载。不幸的是,不活动的视图仍然运行其加载事件,并且控件树中的所有控件都运行其加载。
回到问题:有没有办法阻止子控件为不活动的视图运行?
代码示例:
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设置不可见子控件的可见 属性设置为 False,然后仅在 Visible 为 true 时运行子控件中的 Load 事件处理程序。
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.