ASP.Net过度使用用户控件 [英] ASP.Net excessive use of User Controls

查看:204
本文介绍了ASP.Net过度使用用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的调查广泛每一页上使用的用户控件一个asp.net web应用程序。大多数页面包含10-20个左右的用户控件。用户控制似乎是业务对象的视觉重新presentation(如果是有道理的),虽然在更细的粒度如具有在用户控制其内容的标签控件的每个选项卡。项目本身拥有超过200个用户控件(ASCX文件)。

I'm investigating an asp.net web application that extensively uses User Controls on each page. Most pages contain around 10-20 user controls. The User controls seem to be the visual representation of the business objects (if that makes sense), although at a finer granularity such as each tab of a tab control having its contents in a user control. The project itself has over 200 user controls (ascx files).

应用程序的性能非常差(和原因,我调查)。每个事件(如点击或下拉菜单选择等)需要大约5秒钟的网页加载(10秒,而在Visual Studio)。该应用程序有没有使用Ajax。

The performance of the application is very poor (and the reason I'm investigating). Each event (such as a click or dropdown selection etc) requires about 5 seconds for the page to load (10 seconds whilst in visual studio). The application has no use of Ajax.

跟踪是​​痛苦的aspx页面本身具有在code-后面没有code为用户控件照顾这一切,所以跟踪一个页面需要的是所有的用户控制跟踪语句该网页上。

Tracing is painful as the aspx pages themselves have no code in the code-behind as the user controls look after all of this, so tracing a single page requires trace statements in all the user controls that are on that page.

其实,我认为有其业务code之后的每个用户控件的外观和被重复使用是一个聪明的想法,但过度使用用户控件将导致性能命中?这看起来就像是带有强烈的WinForms背景写的人一个asp.net应用程序的结构?

I actually think that having each user control look after its business code and being re-usable is a smart idea, but is an excessive use of user controls going to incur a performance hit? Does this seem like the structure of an asp.net application that was written by someone with a strong WinForms background?

修改

认为我应该补充一点,我不是质疑使用用户控件(甚至量),而只是是否有一个页面,所有完成的事情(每个用户的控制连接到数据库为例)这么多的一般会引起性能问题...例如,如果只有一个用户控制postsback做一些事情,那所有其他的处理,有些是可见的,有些则不是...... // @大卫McEwing提到,他有40优化的用户控件执行等,但如果开发商基于或WinForms的不熟悉asp.net,再怎么走,以确保每一个被优化...

EDIT
thought I should add that i'm not questioning the use of user controls (or even the amount) but simply whether having so many on a page that all accomplish things (each user control connects to the database for example) will generally cause performance problems...For example, if just one user control postsback to do something, what about the processing of all the others, some are visible and some aren't...@David McEwing mentioned that he had 40 optimised user controls performing etc, but if the developer was WinForms based or "not familiar with asp.net", then how are they going to make sure each one is optimised...

EDIT2

得到一个SQL语句迹后,进行数据相同的呼叫正被执行的每页呼叫5-6次,每次事件作为不同的用户控件要求未存储通常例如数据卡中的各个用户控件(如上所述)作出了同样的呼吁从数据库填充的对象......我真的不是在这里指责的问题(我应该删除的问题?)作为清楚问题的用户控件是不是用户控制,但在这种特殊情况下使用他们......我相信这是过分的!

EDIT2
After getting a sql statement trace, the same calls for data are being executed 5-6 times per page call for each event as the different user controls require data that is not stored commonly e.g. each user control in the tab (mentioned above) makes the same call to populate an object from the database...I'm really not here to accuse user controls of being the problem (should i delete the question?) as clearly the problem is NOT user controls but with the use of them in this particular case...which I believe is excessive!

推荐答案

10-20(甚至上百个)用户控制单是超越平凡。控件本身,和封装的思想的presence,绝对不是你的问题的根源。

10-20 (or even hundreds) User Controls alone is beyond trivial. The presence of the controls themselves, and the idea of encapsulation, is definitely not the source of your problems.

这是很难说的 precisely 的问题是什么,而无需实际分析过程中的应用程序,但根据我的经验,我可以这样说:

It's impossible to say precisely what the problem is without actually profiling the application of course, but based on my experience I can say this:

什么是更有可能的是每个用户控件中的业务逻辑的的具体实施的很差。随着以回发,只要你的描述,每个控制可能看起来回到你的DAL对每个请求自己的数据。这可通过两件事情来减轻

What is more likely is the specific implementation of the business logic inside each user control is poor. With postbacks taking as long as you describe, each control probably looks back to your DAL for its own data on each request. This can be mitigated by two things:


  • 确保用户控件缓存其第一次加载和的从不的重新加载它,除非明确指示(通常是从一个较低的水平,服务的事件)
  • 所有数据
  • 确保控制所有使用一套通用服务,可以重复使用的数据。例如。如果两个控制需要访问客户列表中,并且它们在同一请求会话的上下文中执行,应该只需要一个客户列表查找

  • Make sure user controls cache all their data on first load and never re-load it unless explicitly instructed to (usually by an event from a lower-level service)
  • Ensure the controls all use a set of common services which can reuse data. E.g. if two controls need access to the customers list, and they are executing in the context of the same request session, that should only require one customer list lookup.

这篇关于ASP.Net过度使用用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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