面板和用户控件与负载的用户控件动态 [英] Panel and User Controls vs load User Controls dynamically

查看:158
本文介绍了面板和用户控件与负载的用户控件动态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想动态显示或隐藏一些用户控件。它会更好使用该加载用户控制面板,然后显示或隐藏面板(可见=真/假),或者它会更好在运行时使用占位符和加载(添加)或unlaod(清)他们(LoadControl ())?

If I want to dynamically show or hide several User Controls. Would it be better to use Panels that load the User Controls and then show or hide the Panels (visible=true/false) or would it be better to use a PlaceHolder and load (add) or unlaod(clear) them at runtime (LoadControl())?

A)我有一个使用AJAX的UpdatePanel的页面。该页面有10个小组,每个小组加载用户控件。在后面的code我做可见或不可见一个小组,只显示一次。这个解决方案很简单,因为所有的用户控件的页面,可以很容易地参考他们和他们的内部控制。

a) I have a page that uses AJAX UpdatePanel. The page has 10 Panels, each Panel loads a User Control. In code behind I make the a Panel visible or invisible, only show one at a time. This solution is simple, as all the User Controls are in the page, it's easy to refer to them and their internal controls.

二)内参动态使用LoadControl似乎更复杂一些。

b) Loading controls dynamically using LoadControl seems a bit more complicated.

我不知道是否有比方法的任何利益。 ViewState的问题?渲染性能问题? HTML大小的问题?

I wonder if there are any benefits compared to the method a. ViewState issues? Render performance issues? HTML size issues?

感谢您,

A

推荐答案

我要动态preFER选项A.装载控制和回传重新创建它们总是要复杂得多,而且容易出错不是切换控件中的知名度ASPX的标记。

I would prefer option A. Loading controls dynamically and recreate them in postbacks is always much more complicated and error-prone than switching the visibility of controls in aspx-markup.

我必须承认,我不明白为什么要制作小组和占位符之间的差异。主要的区别是只有一个面板呈现为DIV和一个占位符没有HTML可言。

I must admit that i don't understand why you are making a difference between a Panel and a Placeholder. The major difference is only that a Panel is rendered as a DIV and a PlaceHolder has no html at all.

如果你有他们所有的页面,但只有用户控件单一可见你应该懒加载您的用户控件。这意味着:

You should lazy-load your UserControls if you have them all in page but only single UserControls visible. That means:

奈何在该用户的Page_Load中,但只有当控制器(页)使其可见。因此函数公开给加载其数据并更新自己内心的UpdatePanel在ASCX。然后 - 功能后,从页面调用,控制已变得可见 - 让页面更新周围的用户控件外的UpdatePanel。

Do nothing in the UserControl's Page_Load but only when the controller(page) makes it visible. Therefore expose functions to load their data and update their inner UpdatePanels in the ascx. Then - after the function was called from the page and the control was made visible - let the page update the outer UpdatePanel around the UserControl.

在这样的用户控件既不会被渲染,也没有数据绑定,他们已经作出可见之前,你可以随时干脆直接引用它们。

On this way the usercontrols will neither be rendered nor databound before they have been made visible and you can always simply reference them directly.

让他们通过以下方式进行通信:

Let them communicate in the following ways:


  • 首页>通过功能用户控件/属性

  • 用户控件>页面通过活动

结论:


  • 有关于B选项既不在ViewState中,也不HTML的大小没有任何优势。创建控件动态只有当你真正需要(动态内容)!

这篇关于面板和用户控件与负载的用户控件动态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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