ASP.Net excessive use of user controls

I am exploring an asp.net web application that makes extensive use of user controls on every page. Most pages contain about 10-20 user controls. User controls appear to be a visual representation of business objects (if that makes sense), albeit with finer granularity, such as each tab of a tab control that has its contents in a user control. The project itself contains more than 200 user controls (ascx files).

Application performance is very low (and the reason I'm investigating). For each event (for example, to select a click or drop-down menu, etc.), it takes about 5 seconds to load the page (10 seconds in the visual studio). The application does not use Ajax.

Tracing is painful because the aspx pages themselves do not have code in the code, because the user controls all of this, so tracing instructions on all the user controls on that page are required to track one page.

I actually think that every user control of his business code and its reuse is a smart idea, but overuse of user controls will lead to performance hit? Does this look like the structure of an asp.net application written by someone with a strong WinForms background?

EDIT
I thought I should add that I will not doubt the use of user controls (or even amounts), but simply because there is so much on the page that everything performs (each user control is connected to a database, for example) usually cause performance problems ... For example, if only one user postback control does something, and with regard to processing all the others, some of them are visible and some are not ... @ David Macewing mentioned that he would Lo 40 optimized user controls that perform, etc. but if the developer was based on WinForms or "not familiar with asp.net," then how are they going to make sure that each of them is optimized ...

EDIT2
After receiving a trace of the sql operator, the same data calls are performed 5-6 times per page for each event, since different user controls require data that is not usually stored, for example. 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 blame the user controls for the problem (should I delete the question?), how clear is the problem these are NOT user controls, but with their use in this particular case ... which, in my opinion, is excessive!

+6
performance architecture tracing user-controls
source share
5 answers

10-20 (or even hundreds) of user controls are not trivial. Having the controls themselves and the idea of โ€‹โ€‹encapsulation is certainly not the source of your problems.

It is impossible to say for sure that the problem is without actually profiling the application, but, based on my experience, I can say the following:

It is more likely that the specific implementation of the business logic within each user control is unsatisfactory. If you return messages after you have described, each control probably accesses your DAL for its own data for each request. This can be mitigated in two ways:

  • Make sure that the user manages the cache of all his data on first boot and never reloads it unless explicitly indicated (usually by an event from a lower level service).
  • Ensure that all controls use a set of shared services that can reuse data. For example. if two controls need access to the list of clients, and they are executed in the context of the same query session, this requires only one search in the list of clients.
+8
source share

I will become firmly in the camp of people who suggest that there is no hard limit for the number of user controls that should be used on the page. It appears that application-level tracing is used here, rather than page-level tracing. It may well be that some of these controls are causing the problem. Hell, this may be the only control causing all the fuss. However, since it is impossible to make any assumptions about the level of resource use, that the "average" (if any) user control takes, it is also impossible to offer a limit. Otherwise, we can get similar restrictions on the number of class members or the number of stored procedures in the database.

Now, if we are talking about 20 complex user controls, each of which extracts its own data with each update, and each of them has a bunch of sub-controls using ViewState, regardless of whether it is needed or not, then yes, it problem. However, this has more to do with the overall design than with having too many controls. If, on the other hand, they created a common user control to act like something more than a composite label to the left of the text box (or maybe even every combination of a shortcut + user control) and sprinkled it throughout the application, I can Imagine that you get a bunch of these pages per page, and I donโ€™t understand why this could harm anything.

+4
source share

I understand that you are not familiar with applications that use so many user controls?

It sounds like you can come to the conclusion that this unfamiliar aspect of the application is the cause of the unfamiliar poor performance. Instead of making assumptions, why not try one of the following profiling tools and find out:

All of them can perform memory and profiling of the ASP.NET application processor.

+2
source share

I believe that one of the key goals of UserControls is to reuse code. That is, if the same functionality appears on several web pages, then it is better to create a UserControl for it. This not only allows the developer to write (or copy and paste) the same code on multiple web pages, but it also simplifies maintenance. Any changes made to UserControl are automatically applied wherever UserControl is used. The service developer does not need to worry about finding all the different places that need to be changed in the code.

I'm not sure that single-user UserControl is efficient. They encapsulate and share code that is good on a busy web page.

Can you check if your UserControls are reused or many of them are used only once.

+1
source share

I agree with Saunders that I do some profiling to determine the impact of certain things.

Please note that you can get free stress testing tools for IIS: http://support.microsoft.com/kb/840671

I will say, however, that too many controls are probably not very good, IMHO. Without knowing more, I would presumably say that 20 is too much.

+1
source share

All Articles