如何阻止Web控件加载子控件? [英] How to stop a web control from loading child controls?

查看:102
本文介绍了如何阻止Web控件加载子控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是针对ASP.NET的.考虑一下多视图控件.它具有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?

代码示例:

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

推荐答案

设置不可见的子控件的

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

这篇关于如何阻止Web控件加载子控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆