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?
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
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With