Friday, May 20, 2011

How to choose between ASP.NET Web Forms, MVC, Dynamic Data, etc.

I've just been attending TechEd 2011 North America, and there was a lot of interesting stuff. Among all the sessions I've attended was a Birds-of-a-Feather (BOF) session called "Choosing between WebForms, MVC, WebPages, Dynamic Data and More", which wasn't a success. The whole point in a BOF session is interactivity and almost none were present, as almost no one in the audience had tried MVC. Because of all the buzz around MVC, this was the most asked question, "Why should I convert my Web Forms page to MVC? What do I get out of it?".
Almost everyone looks for a compelling reason to change, but in fact this question aren't answer easily. There are several reasons for this:
  1. It depends on the project.
  2. Even though the industry are moving towards MVC, Web Forms are still actively developed, and will continue to be.
  3. Most things you can do in MVC, you can also do in Web Forms.
I'll try to address each of these points in this blog post, but first lets start with the difference between Web Forms and MVC.

ASP.NET Web Forms has been around from the start of ASP.NET, it has a very similar structure to ordinary Windows programming with events, but are also very different, specifically with the ASP.NET Page Life Cycle. Because of this it can be relatively hard to unit test, there is a lot of classes involved which can't be mocked easily. Even though there are several ways to make this easier, such as the MVVM and MVP pattern, it all depends on the code structure. A well formed Web Forms page can be just as easy as to maintain as a MVC page.

ASP.NET MVC is a relatively new addition to the .NET framework, but has been around for a long time. MVC stands for Model-View-Controller and works quietly different than Web Forms. It has an totally different structure, but it encourages the developer to use a cleaner separation of concerns.

It depends on the project
Choosing between all different alternatives can be very difficult, as most of it depends on the project. For example if you have a existing site in Web Forms, you create a new site or you site it mostly data driven. All of the technologies can be used in all of the situations, they all have they pros and cons. If the site is mainly data driven, such as an interface to a database, Dynamic Data could be an option. If it is a site that enables a lot of data editing, but also functions a "regular" website, I would personally prefer Web Forms. If you would like strict control over the HTML I would prefer MVC. It all depends.

Web Forms is not dead
Because of all the buzz around MVC, a lot of people starts to think "Is Web Forms dead?", and the answer is "Certinaly not". Web Forms are actively develop, and has and will get a lot of new features which only are available in MVC at the moment. The next version of ASP.NET will among others get:

  • Much better data binding, and customization of the data model, same way as in MVC.
  • JS and CSS combination and minification.
  • Better support for asynchronous operations.
Most things in MVC is possible in Web Forms too
Many people using MVC are very happy for the routing possibilities, with friendly URLs. This is also possible in ASP.NET, using MapPageRoute. Controlling the HTML are also possible in Web Forms, although it is more difficult, because of all the controls you don't know how renders HTML. But the possibility to disable the default auto generated control IDs has helped a lot, making it much easier to control the HTML and use Javascript interaction with these.

Conclusion
The conclusion is that there are now conclusion, it all depends on your project and the requirements. It should be noted that it is possible to use both Web Forms, MVC and Dynamic Data in a single web project, if you start with a Web Forms project it requires some modification to the project file, and manual creation of the folder structure, but when this is done, very things works, and you can mix as required. This is very powerful if you aren't allowed or don't have time to convert the whole web site to MVC. If you start with a MVC project, no modification are necessary, you can just start adding Web Forms pages. Personally I use a Web Forms and MVC hybrid website, and it works like a charm. If your Web Forms site works, are maintainable and you know what your doing, I see no reason to change if unless necessary for some reason. There is a learning curve to MVC, it requires a totally different mindset, but if strict control is necessary, I would say "Take a look at it!".
ASP.NET Web Pages are more hobbyist, easy website creation, but leans more towards MVC than Web Forms.
Hopes this post helps anyone to decide what to do, feel free to leave a comment, question or whatever and I'll try to answer.

5 comments:

  1. thanks for your valuble posting,it was very informative.i am working in web design company in chennai

    ReplyDelete
  2. thanks for your valuable posting it was very informative. i am working inCheap Crm Software Company In Chennai

    ReplyDelete
  3. Great posting, Really very useful sharing. I Am working in a CMS In Chennai.Here providing very low cost price, CMS and responsive webdesign. Just send your mail, this is mail id info@excelanto.com.Do You have Any Information Let me now.....044-42127512

    ReplyDelete
  4. Superb post man, really helpful and valuable posting, u should try ASPHostPortal for experienced hosting provider

    ReplyDelete