12,066,626 members (56,831 online)
It’s been a long time I have been working as an ASP.NET developer and I do enjoy writing web apps using web forms.
In 2008 Microsoft came up with something called as ASP.NET MVC and I was quite amazed about the fact “Why one more ASP.NET technology required” and many people still pondering same.
|Many people say ASP.NET MVC replaced ASP.NET Web Forms. But that’s not true. Both have their own pros and cons Nobody can tell or teach us what to use and when, but we can discuss about some facts which will help us to make choice between both of them. And this article contains same.|
|We also try to find answers for some questions like,
If you are advanced or experienced ASP.NET MVC developer, who already know MVC very well then this article will help you to revise your concepts.
|Microsoft initially came up with something called
Visual. With the help of technologies like Visual Basic, Visual C++ Microsoft enabled RAD (rapid application development) of Graphical User applications. Features such as Drag and Drop and intellisense made developers to focus more on the business functionality of the application rather than on UI design.
But this technologies were limited to desktops, when it comes to web the only option left with Microsoft was ASP.
When we say web technologies, we have classic ASP, php, jsp,ROR, ASP.NET Web Forms, ASP.NET MVC and many more. Classic ASP is one of the web technology introduced by Microsoft. Biggest pain point with the classic ASP was spaghetti code and maintainability. Let assume a scenario where you have some text boxes and a button. On button click you validate the data with the server and if validation succeeds data will be stored into database and in case it fails, error message will be shown to user in the form of red colored label. You know what’s the biggest problem with this scenario is? You have to do lots of stuffs by your own.
(Using Ajax is an alternate method. Here I was trying to explain the manual work need to be done with classic ASP)
Technologies like Visual Basic are limited to standalone applications, when it comes to web, only option left with Microsoft is classic ASP.
When we talk about Web and Desktop, two things which should be considered are
Web works on HTTP which is completely a stateless protocol. We will be having request and response independent of previous request and response. Unlike desktop no variable values will be preserved and no complete event driven programming model. Like desktop it will wait for user inputs but every user input and interaction act as a new request (get/post) to server.
Finally Microsoft came up with something called ASP.NET Web Forms, considering rapid application development and easy learning in priority.
ASP.NET is a Microsoft’s Web application framework built on Common language runtime for building dynamic web sites using one of the programming languages like C#, VB.NET etc. It supports 2 models Web Forms and ASP.NET MVC.
Microsoft first brought out ASP.NET Web Forms from ASP which solved lots of problems by creating higher level abstraction over stateless web and simulated stateful model for Web developers. In web forms concepts like self postback (post form data to same page) and ViewState (maintain control values during postbacks) are introduced. And the most interesting part is it’s not required to write even a single line of code. With Web Forms Microsoft tried to bring the Visual Basic model into web.
Let’s talk about advantages and disadvantages of Web Forms.
Developer will no more rely on POST, GET methods for handling user interactions with server. For example she/he will drag control (say button) to page, just double click it to generate the code block for handling user’s click on server, write down the logic inside it. That’s it. She/he is not concerned with what happens inside.
There is no fixed predefined Project Architecture for creating web applications when it comes to Web Forms. Developers have full flexibility for choosing their own architecture.
One may use basic three layered architecture dividing the system into UI, Business layer and Data access layer or a more advanced one like Model-View-Presenter. Even one may choose only code behind and write everything there which is not at all considered as good practice. Code behind is tightly connected to UI, ending up with some presentation logic.
In Web Forms code behind ends up with lots of event handlers, making automatic unit testing an impossible task.
Note: as per my knowledge even with the help of mock testing (using MOQ or rhinomoq) we can’t mock ‘sender’ and ‘eventargs’ in event handlers.
And when we talk about employing TDD, unit testing code behind (presentation logic) becomes very important.
ViewState becomes solution for some problems with classic ASP but it also becomes an issue. ViewState is stored in the page itself resulting increased page size so reduced performance.
Let’s talk about another example where we are supposed to build 2 UI
URL’s are pointing to fixed ASPX pages which might be decorated with some query string. They are not user friendly and affect SEO.
ASP.NET 4.0 has come up with some good features to overcome some of the above problems
Even after the evolution of the revolutionary features of ASP.NET,
MVC is an architectural pattern which is has been around for sometimes now.
Many are using it including Java. It’s not new concept which Microsoft brought it up. ASP.NET MVC is something we should talk about. But prior to that lets clear some terminologies including MVC.
ASP.NET MVC is a Microsoft’s one more Web application framework designed with separation of concerns and testability in mind. It is built on CLR and completely based on MVC architecture and so we think in terms of controllers and Views. ASP.NET doesn’t have support for ViewState and server controls, so we get feel of old web here. Let’s talk about Advantages and disadvantages of ASP.NET MVC
|One of the advantages of using ASP.NET MVC is it enforces separation of concerns. So there is very less chances of getting things more complex.|
Also user-friendly and readable URL improves SEO.
This was for get request, same happens for post. Only instead of putting URL in the browser user will do some action on already requested page and flow start with the controller. Actions like clicking button, changing drop down value etc.
Each can be the “best choice” for a particular solution depending on the requirements of the application and the background of the team members involved. What to choose and when has more to do with business prospective than which one is better than other. When facing a decision to choose between ASP.NET Web Forms or ASP.NET MVC it is important to know that neither technology is meant to replace the other.Two important factors you should consider while making the choice is
Other than these, what you can do is, write down all your project requirement and try to compare them with Pros and Cons of both Web Forms and MVC and if possible try to ask yourself following questions and point MVC and Web Forms accordingly
I think you should have equipped with enough information to make a decision what is best for your project. The complete decision depends on your team and project requirement.
Hope all of you enjoyed reading this article. Thank you for the patience.
Also go through our complete step by step series of MVC(Model View Controller)
Click here for see MVC video step by step.