Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best Practices for ASP.NET Webforms Project structure

When using ASP.NET webforms, I see two main ways to structure a project:

1) Have a lot of .aspx files (including code behind files) and maybe some .ascx files (with code behind files.

2) Rely on a lot of .cs files (class files), and have the classes construct everything with Controls.Add(), etc.

The first method above results in a lot of aspx and ascx files and very few .cs files. The second method above results in a lot of .cs files, but very fewer aspx and ascx files.

Is there a "best practices" way to structure project? Does Microsoft recommend one of these techniques? Is there any information on which of the two styles is used more commonly?

like image 633
flying227 Avatar asked Jul 26 '12 16:07

flying227


People also ask

What are the top 10 best practices in ASP NET Web development?

Let’s talk about the top 10 best practices in ASP.NET web-based application development. 1. Embrace Latest Version of ASP.NET Core Every release of ASP.NET Core comes with new features and upgraded performance. So, to develop a web application with ASP.NET, make sure to pick the latest version of ASP.NET. 2. Avoid blocking calls

How do you structure your webform project?

When using ASP.NET webforms, I see two main ways to structure a project: 1) Have a lot of .aspx files (including code behind files) and maybe some .ascx files (with code behind files. 2) Rely on a lot of .cs files (class files), and have the classes construct everything with Controls.Add (), etc.

How to improve the performance of ASP NET Core web application?

Every release of ASP.NET Core comes with new features and upgraded performance. So, to develop a web application with ASP.NET, make sure to pick the latest version of ASP.NET. 2. Avoid blocking calls ASP.NET Core web applications often lead to poor performance due to blocking calls.

What is a new ASP NET Core project?

A new ASP.NET Core project, whether created in Visual Studio or from the command line, starts out as a simple "all-in-one" monolith. It contains all of the behavior of the application, including presentation, business, and data access logic. Figure 5-1 shows the file structure of a single-project app.


2 Answers

I would stick with the first approach. Some controls are extremely tedious (or difficult) to be created progamatically.

Take the GridView or ListView for example, create an *.aspx page with a GridView which has custom templates with template columns. Then run your application, find the *.dll in the ASP.NET temp directory, decompile the class and look how messy and complicated is the code. It would be very difficult to maintain it over time and/or make changes.

On the other hand, having some declarative code isn't bad as long as you try to maintain the balance.

like image 190
Wiktor Zychla Avatar answered Sep 20 '22 12:09

Wiktor Zychla


If you haven't done so, check out ASP.NET MVC. If you cannot opt for MVC you can implement MVP pattern with ASP.NET WebForms. These two patterns provide good way to separate presentation, model and routing.

like image 36
oleksii Avatar answered Sep 18 '22 12:09

oleksii