Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

User Control refactoring

This is a performance issue and also a refactoring problem.

I have a .NET user control (UCA.ascx)... which in turn uses 5 other User Controls internally. Each of these user controls run into greater than 2000 lines of code.

The web page loads UCA.ascx first ... then the other 5 user controls are loaded dynamically based on actions in UCA.ascx. The code-behind of of these user controls use DTOs and have business logic in them.

The main problem is to resolve the long loading time and delayed operational time (due to postbacks). To resolve this issue, I would need to make sense of the code first.

  • So, is there guidance on what should be and what should NOT be in the user-control code-behind codebase?

  • Is there a tool-driven or easier way to refactor large, unwieldy user controls?

like image 430
Sartorial Avatar asked Jun 16 '26 00:06

Sartorial


1 Answers

  • Optimally, there should be no business logic or data access logic in your presentation layer at all. The code in your presentation layer should consist only of code to retrieve business objects and bind them to the appropriate controls on the page.

  • ReSharper has some built-in refactoring tools where you can extract methods from your codebase, but generally speaking, refactoring like this is delicate and should be approached very carefully, with forethought to how you're approaching the redesign.

As you refactor, try to keep SOLID principles in mind and add unit tests wherever it's feasible.

like image 178
Daniel Mann Avatar answered Jun 18 '26 14:06

Daniel Mann



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!