ASP.net MVC Vs ASP.net Web Form

 
Software Architects have been involving lot of debates about different approaches and architectures. Some of the examples are ORM Vs Store Procedures, REST Vs SOAP, etc. There is a debate happening inside the Microsoft community about ASP.net web form Vs ASP.net MVC. Many people thinking that ASP.net MVC will be replace webforms at least eventually and others are thinking that ASP.net MVC will not be replace webforms. Will ASP.net MVC replace webforms?. ASP.net MVC is an alternative approach to webforms rather than a replacement. It will not replace webforms and webforms will not replace ASP.NET MVC. The fact is that ASP.NET MVC and webforms will co-exist and that ASP.NET MVC is not a replacement for webforms. If you prefer ASP.net MVC use it and you feel webform is more comfortable, you can use it. . Both approaches are just choices and different approaches and choices are good things. Different choices are available for other platforms especially in the Java platform.

Problems with ASP.net Web Form

What are the problems with webforms? In webforms, Microsoft has tried to make windows form model development for web application development. That model was attracted lot of windows form developers especially VB 6.0 developers. Many of VB 6.0 developers had moved to ASP.net web development without knowing the basics of HTTP and web. For simulating windows form model development experience, webforms introduced event-driven approach and also introduced Viewstate and Postback. The end result is that web forms breaks the stateless nature of the Web. Both Viewstate and Postbacks have been made lot of problems and increased complexity of the web application development. Many web pages having hundreds of KB size of Viewstate that affected the performance of the applications sometime. Developers do not have the control of the rendering HTML of web forms and Server controls that render html with mixed inline style and deprecated tags that does not follows standards. Another problem with Web Forms is the integration of JavaScript frameworks due to the naming conventions of rendered HTML. The page life cycle of the Web Form is too complex and has the tightly coupling between all things in the ASP.net framework and a single class is used both to display output and handles user input. So unit testing is almost an impossible task. Today unit testing is very important in modern software development especially when we following agile methodologies and practices. Since web is a stateless thing, Events, Postbacks and Viewstate are not a good way. Today many ASP.net web form developers are facing different type pf browser compatibility issues when developing public face internet applications

The ASP.net MVC way

The ASP.NET MVC simplifies the complex parts of ASP.net Web Forms without any compromise of the power and flexibility of ASP.NET platform. ASP.net MVC implements Model-View-Controller UI pattern for web application development that lets you allows to develop applications in a loosely couples manner. MVC pattern is separating the application in three parts- Model, View and Controller. A view is responsible for rendering the user interface (UI) of the application and it is nothing more than html templates that filled with application’s data passed by the controller. The Model implements the logic for the application's data and it represents the business objects of the application that using the View for rendering user interface. Controllers are handles and responds to user input and interaction. The web request will be handled by the controller, and the controller will decide which model objects to use and which view objects to render. The MVC model replaces the Web Form events with the controller actions. The main advantages of the MVC models are clear separation of concerns, unit testing facility, and more control over the URLs and HTML. The MVC model does not use Viewstate, Postbacks, Server controls, and server-based forms that enable full control over the application and html rendered by the Views. MVC model is using Representational state transfer (REST) based URLs instead of file-name extensions used by the Web Form model so that we can make search engine optimization (SEO) URLs published by the application.

The below code shows the implementation of MVC application.

ProductsController.cs (Controller)

 


In this sample, I have used extension methods to the HtmlHelper class to display ordered list of information.

OrderListExtensions.cs


Category.aspx (View) 

 

Advantages of MVC Model

  1. Enable clean separation of concerns (SoC) .
  2. Enable full control over the rendered HTML.
  3. Enable Test Driven Development (TDD) (built with TDD in mind).
  4. SEO and REST friendly URL.
  5. Easy integration with JavaScript frameworks.
  6. Support third-party view engines such as NVelocity, Brail, NHaml.
  7. No ViewState and PostBack events.
  8. Follows the stateless nature of web.
  9. Extensible and Pluggable framework. 
  10. Ideal platform for Web 2.0 applications.

Advantages of Web Form Model

  1. Provides RAD development.
  2. Easy development model for heavy data-driven LOB applications.
  3. Provides rich controls.
  4. Familiar model for windows form developers.

Which is the best approach?

The choice would be vary on different people. If you want more control over the HTML or you want Test Driven Development (TDD), or you care about web standards, accessibility, or you want to build SEO based URLs, you can choose MVC model. If you want rich controls and state oriented event-driven web development, you can choose Web Forms model. If you feel more comfortable with MVC, choose that model and you feel Web Form model is more comfortable, choose that model. Both are just choices. If you start your career with ASP.net Web Forms and do not have full knowledge of Web, it will be very difficult moving to MVC model.

I prefer MVC over Web Forms and I feel that Microsoft is going to a right direction through MVC. Its technical features as well as the open source nature are attracted me a lot.The MVC model allows me full control over the HTML and enables Test Driven Development (TDD). We can easily integrate with jQuery and other JavaScript frameworks with MVC. Using extension methods of C# 3.0, we can make powerful and rich HTML helper methods. I believe that tesatbility, refactoring capability and maintainability are the main factors for a successful project and prefer these factors than RAD capability. The MVC model allows to build highly testable, maintainable loosely coupled applications with good practices such as TDD, Seperation of Concerns (SoC) and Dependency Injection (DI). You MUST use ASP.NET MVC for public face internet applications.

101 Comments

  • I'm studying CakePHP which brings MVC to PHP web application development. This will help me to understand Model-View-Controller without getting into ASP.NET beta technology. I don't plan to get too deeply into CakePHP. But it is easier than trying to learn MVC using Ruby On Rails.

  • Thanks for the post. It was easy to understand difference and why to choose what after reading.

  • More control of the generated HTML for MVC, yes. But the embedded HTML tag is really ugly. I think we need an abstraction layer to get rid of those HTML tags.

    Ideally, you will have a GUI designer and layout your page and the plumbing code for controller, model, view should be automatically generated for you. If I have to write the HTML tags all over the place, I would rather work with some other languages and tools.

    What about a side by side comparison to implement a gridview like UI using both WF and MVC? It will take tons of code and effort to do that in MVC. Yes, you can write test code easily, but you have to realize that by using GridView for WF, all the tests have been done for me by the people who developed GridView versus you have to write your test code to test your "gridview" like construct in your MVC code.

    ASP.NET MVC at the current stage should not be used for any serious enterprise level development. It's only good for "Hello world" type of academic excercise.

  • Thanks for the post.I think MVC is the best way to go.

  • Thanks for the article,

    For those of you who assume that MVC isn't capable of developing "real world systems" Your wrong- I'm using MVC to build a production system at work, and it's working out great. I don't even miss being able to drag and drop grid views! (and no, it doesn't take that long to write a for loop to create a table in HTML). Yes I understand the gamble of the ever changing previews, but it hasn't been a problem so far.

    Keep in mind that the proprietary web implementations of MS (abstractions from HTML, css and javascript etc) was part of the problem with web forms in the first place. We don't need to be abstracted from what the end product will be.

    The fact is I'm getting more done, faster with ASP.NET MVC and there's been little compromise.

    Granted, its not as mature as web forms, but its close relationship with core web technologies makes it easy to step outside the framework and take over, which can't be said with "Old School" ASP.NET ;).

    ...I hate to be "That Guy", and I know it's not the point of this article but ORM's and Stored procedures aren't mutually exclusive.

  • Steve, I got the same thought as you. WebForm is too heavy if compare to MVC.

  • MVC pattern is the better way to develop web applications and this has been proved by Ruby on Rails (RoR) for the past few years.

  • Indeed the MVC Pattern is the "Proper" way to develop all applications, not just web based. Ideally we'll move to a framework where the views can be swapped out (web for windows etc.) leaving the model and controllers untouched.

    It's been around since the 70's but credit should be given to Jakarta Struts (Java) for making it popular for web development 8 or 9 years ago.


  • "(and no, it doesn't take that long to write a for loop to create a table in HTML)"

    yes, but gridview is not just that. and designers don't like for loops. it's a programmatic term and they are not programmers.

    MVC don't have to be anti webforms. you should check DynamicData. It's webform using models, views and controls.
    maybe you should try achieve the same result in ASP.Net MVC. DynamicData will do it for you in secounds (and you have full control over the output) while you will spend days with ASP.Net MVC, working on the same task.

    I realize DynamicData can't be used for front end sites. It was just an example of MVC used in WebForms.

  • MVC is a step back to the dark ages of ASP if you ask me. Viewstate is not evil. If you want to keep the size of the page down then there are various avenues open e.g. store it in a SQL Server table, use IIS compression etc etc.

  • Hi, interesting article. I am new to ASP.NET MVC and have came from a Windows development background so the Web Forms approach of ASP.NET is more my thing.

    However...

    I'm seeing the advantage of the MVC and I think when combined with jQuery using ASP.NET MVC will be very straightforward and powerful.

  • New articles about ASP.net MVC

    ASP.NET MVC Tip: Ajax and Validations using jQuery -
    http://weblogs.asp.net/shijuvarghese/archive/2008/10/01/asp-net-mvc-tip-ajax-and-validations-using-jquery.aspx

    ASP.NET MVC Tip: Dependency Injection with StructureMap - http://weblogs.asp.net/shijuvarghese/archive/2008/10/10/asp-net-mvc-tip-dependency-injection-with-structuremap.aspx

  • Thanks for this post. I am in the process of enumerating the advantages of MVC over webforms and came across this and it helped me make a decision.

    I used webforms for more than 6 years now and definitely it has matured into a very stable platform, with myriad of third party controls and fast development cycles. In this respect, I tend to agree with most of the points made by commenters, that most of the list under problems with webforms, already have solutions, be it viewstate that can be disabled or search-engine friendly urls(using httpmodules).

    Coming to MVC, it does hold promise as it has been proven by ROR
    and many other python & php frameworks(I did work with ROR & Django). However, in its current state(beta) it is still too early for prime-time.

    If you were to compare webforms and asp.net MVC, the advantages/disadvantages are not really the manner to approach,
    it is just that webforms is like a young adult and asp.net MVC is
    still an infant.

  • "MVC don't have to be anti webforms."

    Exactly!!
    MVC /MVP are just patterns! You can and (always could)
    implement these testable patterns with web forms if you choose to.

    MVC is just another development option. For some projects (and developers) it will be more suitable, for others web forms will.

    For wide audience facing “web sites” I’d say MVC is a good option.

    For line of business web based applications, I’d insist on all the benefits of a well constructed web forms architecture, still using a MVx pattern for the UI layer.


  • ASP.NET MVC Tip: Dependency Injection with Unity Application Block http://weblogs.asp.net/shijuvarghese/archive/2008/10/24/asp-net-mvc-tip-dependency-injection-with-unity-application-block.aspx

  • @Iain,

    Implementing testable MVC pattern for a web form would be very difficult due to its architecture. The main problems are Logic resides in code-behind has tightly coupling between view and code-behind. And has Lack of interfaces or Abstract Base classes that required for better testability.

  • @lain

    ASP.NET MVC is not for everyone. It is just an option and it is not a silver bullet for every applications. MVC framework will appeal some people and some people will prefer web forms. Different people have different objectives while developing applications and people are adopting different methodologies and practices for software development life cycle. Someone prefer RAD and at the same time others would be prefer loosely coupled architecture and testability. If RAD is your primary concern, I would say, web form is good for heavy data driven LOB applications. And MVC is good for public face internet applications and web 2.0 model applications. For LOB applications, you need to have a infrastructure framework for MVC to show complex data. But you can do it. If you are not doing Big Design Up Front (BDUF) methodology, you must use MVC model for TDD.

    The MVC framework is just reached the Beta stage. But some people already started with MVC. http://stackoverflow.com/ is a killer web 2.0 application developed with ASP.NET MVC.

  • Please dont get me wrong, I think we are i agreeance on many fronts. I totally agree that MVC offers another and very very valid development option. As you said there is no silver bullet either way.
    The point I was tryin to make is WebForms is far from a failed architecture and there are pros and cons each way.

  • I am an ASP.NET developer start my career with classic ASP. The web form model is sucking me due to its leaky abstraction. I will use the new MVC model. RoR has proved that MVC is a successful pattern for web applications.

  • ASP.NET MVC is ROCKING!!!!!!!!!!

  • No one ever mentions that Java has had multiple MVC frameworks for years (Struts, JSF, Spring etc). Coming from that background, I found WinForms model really clunky for the web. It is a hack to get Windows programmers comfortable with the web. I see ViewStates of 300KB or more everyday at my job and that just gives me heartache. Not to mention that many links are not crawl-able due to postback. Sure you can avoid these problems with discipline, but the architecture itself does not encourage it.

    Hope we see leaner web apps through adoption of MVC.

  • well.. looking into future ..dont think it'll take 2-3 years may be 5 yrs, when internet technology will have more bandwidth and speed for data transfer via internet..
    ... web-form will win the race..!!

  • I have read quite a bit on this pattern, and although I haven't used it in a project yet, I am concerned about the time it will take to implement as well as the inability to visualize the UI in design mode. Many of the problems it solves I don't see as problems in the vast majority of web applications I have worked on.

    I am a big fan of IoC, and strong believer in seperation of concerns. But I also believe there needs to be balance. Developers are usually very bad designers. I like the idea of designers using drag and drop tools to create the UI, think about UX, and doing it in a way that the designer doesn't need to concern themself with complex development. I also like to easily show a business analyst or client what the end product will look like without actually tying everything together.

    Can you point me to an "elegantly designed" web application that followed the MVC pattern? I can't imagine a designer using Expression * to design the layout while working with a developer. Can you also quantify the impact on a project in terms of time?

  • I see the need for both, but I have to say this article is one sided. It started out saying how both are needed, but in no way shows the cons of MVC or the pros of web forms. It’s like a C# dude writing an article how VB and C# are equal and then downing all the VB things like optional parms. Well I guess the good news is that C# 4.0 will make C# VB with curly brackets, so at least that bashing will end.

  • Nice post !

    Thanks for the hard work and the valuable information for sharing with us.

  • I have been using MVC and it is better than webform model.

  • that's a quite good explanation..most of them seem to think Web forms are good... but its makes your Job tough when its come to separating the Business Logic and the HTML.. just Think i have seen lot of people writing Business Logic in the code behind Page and using the business Layer to Just call Databases with some parameter sending option..but tats where the concern is ... if You want to expose your Business logic as the service then You have to look at the dependency.... i am not saying Asp.net MVC can provide it by default..but its Provides good platform to do...

  • @Lars-Erik Kindblad
    Web form is not extensible and pluggable as MVC. Because the Framework has lack of interfaces and abstract classes. Can you change the default view engine of webform?
    The MVP pattern enables you Testability in webforms but at the same time the framework is not developed with TDD in mind. From TDD perspective, MVC is great and RAD perspective, webform is great.

  • Great article. ASP.NET MVC is natural way for web development.

  • I believe you have some really good points here. I don't think "Replace" is the right word. MVC Attracted me to .Net as it was my deciding factor in some of the applications I am working on. I also feel forms has its place, but I believe their place is in small applications (though larger ones can be pieced together).

    I think the more appropriate large application structure is MVC though, why else spend so much making it happen. I believe MVC will have some Ole Faithful "Java" developers coming this way (if it hasn't already).

  • I see the MVC model as much more powerful, but yet much more expensive (at least nowadays) option. It is much more powerful because of total freedom to create from scratch. And this is the reason why it'll be more expensive to develop. Another thing that I see, - web sites with the extreme traffic can save money on number of boxes, needed to handle this traffic.

  • This is a great artcle, thanks. However, I'll stay with my ASP.NET Web Forms for simplicity reasons until the ASP.NET MVC Framework is matured enough.

  • Great article. I will choose ASP.NET MVC over webform.

  • Good article and great comments contributed by other fellow developers. Helped me a lot.

  • I definitely see value in .Net MVC. But it does not seem like it should be used for every project. Saying that you can easily change an app from web to windows or to a cell phone fails to mention several things.


    The MVC application has to be written correctly for it to be easily changed. Most developers are of average skill, so expecting a team of developers to think and code perfectly for each use case under tight deadlines to allow proper separation of concerns assumes a lot. There are always issues that pop up in even the simplest upgrades/migrations, so selling MVC by saying that you can change views easily is an over simplification.

    Also, how often do you develop a web app and then then suddenly decide you want to make it a windows app or a cell phone app? Only rarely would this occur. If you are starting a project then you would have considered this ahead of time and put the required effort and plannig into the project from the start. Also, I would think if you wanted to create a cell phone app you would want to use an SDK specifically for the platform in question. So just because you can do something because of MVC doesn't mean you should.



    Web forms and MVC both have their place. If you choose the wrong one for your project then life can get ugly.

  • Thanks for the post! Your information helps me so much in decision between MVC and WebForm.

  • informative content. good work

  • I am trying understand MVC but dont end to get it. If presentation is totally separated from the controller how is possible , tags and others are included in the OrderListExtensions.cs example you provide??? Sorry for the question if it's too obvious, but I am newbie.

  • Anyone thinks they will more than 50% of mvc programmers anytime soon?

  • thanks for taking the time to write this article. I am a professional developer with 11 years of web development experience and with the last hour and half or so of digging into MVP with intent of finding out its usefulness for the kind of work i do day in, day out i have come to the following conclusion

    MVP is not a challenger to the productivity of using WebForms so the .net developer can dispel with any such concerns and get on with their jobs. the reason i say this is because MVP for the non .net developer is a solution package for languages like PHP, easing the application building process and sophistication over basic CGI like capabilities

    experienced .net web developers will achieve most of the points listed as advantages of MVP with savy WebForm development. i disagree with you that the webform page life cycle is too complex and urge you to master it and enjoy commercial productivity from n-tiered development. those that have spent years using classic asp javascript html etc to build business applications will relish the power of webforms

  • nice article & comments! nothing is complex once you master it :) but if you see internally how things works - when you talk about asp.net gridview, its a bit ugly code comparing to asp .net mvc. any component/ 3rd party component developers will agree on this. and the SoC is damn good thing in asp. net mvc. and if you worry about writing more code for creating your own controls, you got 3rd party vendors who already developed asp .net mvc grid and other controls. and i am not saying that asp .net mvc is a replacement for asp .net – but its just a better way of doing :)

    happy coding!

  • I am new to MVC and haven't formed an opinion or take decision on which way is better. With MVC, is it possible to find what caused the Post to occur considering I have multiple submit buttons (each one doing a separate action at the server end) on the form.

  • @Manoj You can possible to use multiple submit buttons. Check this link http://stackoverflow.com/questions/442704/how-do-you-handle-multiple-submit-buttons-in-asp-net-mvc-framework

  • Anybody who says you can't build enterprise applications with MVC and should only use it for hello world is not getting it at all and is not adding to the debate at all. I am developing a web application for a large enterprise using MVC with no problems at all.

  • ASP.NET web forms with a corrent MVP implementation is vastly superior to MVC in many ways. MVC couples with view too tightly to the ui while MVP provides a distinct separation between the view and the implementation of th view. This allows extensibility across different types of apps - ASP.NET web forms, WinForms, WPF, etc. Microsoft is placing too much emphasis on producing tools and not enough on teaching developers sound development practices and the importance of understanding design patterns.

  • Furthermore, ViewState is not evil. If used correctly it is incredibly useful.

  • I'm studying CakePHP which brings MVC to PHP web application development. This will help me to understand Model-View-Controller without getting into ASP.NET beta technology. I don't plan to get too deeply into CakePHP. But it is easier than trying to learn MVC using Ruby On Rails.

  • Outstanding Article. Simply the best. Thank you man.

  • Where is your "model" in your code sample?

  • The more i read about MVC, it gives me a feeling, MVC is the right way to go. Webforms look attractive but is what VB6 was to MFC developers.

  • Right Explanation...

  • A good article to understand the difference between ASP.net MVC and ASP.net Web Form

  • People can debate this all they want but it all comes down to the environment you work in. If you need to get a product to market quickly, WebForms is for you. If you have the time and need all the control that MVC offers, MVC is for you.

    In my current environment, WebForms is the right choice. We have to deliver products to our customers quickly. They do not care about anything but the fact that it does what they need it to do. It might be a little heavier but they don't know, don't care, and don't notice.

    As far as "truly stateless", I consider that a weakness of the web not something to get back to. I mean...really...? This is not a good thing.

    MVC will evolve and have some RAD features in the future and will be the way for me to go. I have to get out apps now though. Bottom line: If the apps are not going out no money is coming in.

  • Microsoft has no direction... after 10 years.. they are going to back to MVC???!!!! what I should do with all the applications I developed.. port them..keep them with crappppy view state issues

  • ASP.NET MVC is not originated from Microsoft and built by Microsoft. MVC is a design pattern. If you know software design principles you can create your "MVC" or another solution for web application.

    For 3 years, i have been using MVP (model view presenter) design pattern using "web form" and i found it really usefull. MVP can support test driven development and seperate business logic, user interface and date layer easily.

    Also, in my opinion, viewstate and postback sometimes are really pain. But you don't have to use them. You can disable if you want. When i use web form, i rarely use viewstate and postback. But it doesn't mean, viewstate and postback are totally useless.

    Until now, i learnt that if you build web application you should know how http works.

  • Since Microsoft has introduce this new MVC, what will happen to Webform application. would there be any innovation on Webform architechure?. Is there a way to build ajax application using MVC?

  • 1. Webforms don't "break" the stateless nature of the web.

    2. When you're building websites and using http, you're using a stateless protocol. Period.

    3. You can try to simulate state on the web, but state is not affected by implementation, regardless of whether you're using MVC or webforms.

  • Thanks for the straight-forward article on MVC.

    I have to echo the concerns of some of my fellow programmers in that embedding script within the view feels like a return to the "ol' ASP days".

    When I moved from ASP to ASP.NET back in 2003, I have to admit that, at first, I didn't want to leave the embedded scripts. But, I quickly appreciated the clean seperation of logic and HTML.

    Under the advantages of MVC, bullet #3, in my opinon, would not seem to make sense for most WAP. SEO would not matter for internal applications.

  • Kudos for your article

  • Now i m starting learning MVC asp.net.I think Microsoft released new Technology are to help web developer.

  • This article is so biased that i dont have words to describe it. Somebody tell me that Why with every new technology it is necessary to find faults with the old one?

    1. Webforms to date provide the state to the stateless web. We all know that in business applications we have to maintain the state. what action was performed and what actions are available based on the previous actions taken.

    2. Viewstate makes page bigger but it seems the writer has never tried to find out so many solutions of keeping viewstate out of the page? or disabling the viewstate altogether.

    3. No control over server control html. well why in the RAD anyone would be intrested to control the html rendered by server control? if they do need they always have the option to rollout their own server control or user control.

    4. ASP.NET model is there to attract Vb6.0 developers? This is complete BS. What are his views about C#? to attact C++ developers? Please come to the real world. We developers choose tools & languages according to the requirements not becuase we are attracted to something.. complete nonsense

    5. Postback and viewstate increase complexity??? Well now in MVC you have a lathe machine to start with. you must be very happy now!!!

    5. Unit testing is impossible? well it is possible and the author has to realize that there are numerous tested business applications working on internet.

    Please if you dont like something say "you dont like it" dont say
    "Nobody likes it".

  • @Merc - I am not a against a specific framework and I believe that every framework has its own advantages and limitations. There is not any silver bullet for a particular problem.If you prefer ASP.net MVC use it and you feel webform is more comfortable for you, you can pick webform.Both approaches are just choices and different approaches and choices are good for developers which have different objectives and different development styles.

  • I have been wondering what all the hoopla is about over ASP.NET MVC so I decided recently to take a deeper look at it. What I found was simply a new twist on an old paradigm, "Classic ASP", which I enjoyed working with since it allowed me to create modularized applications by simply embedding all my HTML within "Response.Write" statements making the code far more readable than had I mixed script and HTML together.

    To call ASP.NET MVC a new paradigm is not correct. It is an old one that is being discovered for the first time by younger technicians that have never programmed the web the way we did it years ago.

    You CANNOT change the way you program against the web because as an environment it has never changed itself and probably won't in the foreseeable future. As a result, it makes little difference in the methodologies used since in the end all of them basically do the same thing.

    That being said there is nothing wrong with either model; Web-Forms or MVC. It is a matter of what you prefer and what you require. That is it. The rest of the discussion about which is better or which is good or bad is simply irrelevant...

  • Thanks for the useful conversation. It helped a lot. My point of view is if productivity matters to you, you should chose Web Forms. I think MVC is too young and it needs more time to get mature and as productive as Web Forms.

  • Agree 100% with Steve Naidamast. I've been using MVC for over a decade with various platforms and languages. With ASP.NET webform projects, it's very much possible to apply MVC and it is something i have always done. That meant i did not use a number of the 'cool' and rad stuff provided by webform (such as client side r/w binding or querying), but i did get a lot of from those controls which i did not have to write html for and which could perform readonly binding to a viewmodel (same thing MVC advocates). You can architect a system with ASP.NET webforms that clearly and cleanly separates UI, Business and Data.
    I too am a bit perplexted at how many folks are seemingly implying this is something new or something that could not be achieved before WITH EASE.

  • Hi Shiju, In Advantages of MVC, In 7th point you have mentioned that No Postbask is required.
    Does this mean that we dont need AJAX now?

  • Thanx Buddy
    this article is really helpfull 2 me
    2 enhance my knowledge and clear my views about MVC.

    Thanks & Regards
    vipin bardia

  • Is it necessary to learn MVC for ASP.NET Webform developer future survival?

  • I have worked on both but I am comfortable with MVC compare to Web form due to power of HTML.

  • I don't know that I can best enumerate the pros and cons of each. All I know is MVC has made me not hate developing Web UIs quite so much.

  • One thing is missing in all these comparisons:

    the business side

    None of the criteria mentioned actually reflect the business side of the decision making. A comparison of the time/effort required to code the same app in both frameworks is missing. The business is never interested in sessions, postback, control over html, views etc. if the MVC approach drives the cost up 2x, then none of the ‘nice’ features of MVC matter. Software costs are driven by labor costs – and it’s the single biggest decision point on selecting technology.

  • Agree with dizzy0ny.
    So many people "parrot" on about SOC and testability, now they have jumped on the ASP.Net MVC bandwagon, though from comments read it is obvious they had never understood these things prior, and still dont really understand n-layer design.

    Ive read comments along the lines of "ASP.Net MVC is better, because now all business logic sits in the controller not in viewstate" WTF?????

    rule of thumb: Picking the new platform wont stop bad developers being bad developers, even if a design pattern ancrynom is used in the platform title.

  • In my opinion, the question is becoming blurred with a lot of the cool features of MVC making their way into Webforms. ASP.NET 4.0 added URL Routing, reduced ViewState, and greater control of the HTML mark-up produced by many ASP.NET controls, now the next version of Webforms will incorporate many more MVC features into Webforms. http://bit.ly/dNhBd8

  • From the tutorials I've started to do on the ASP.Net MVC site, there is, at least, so far, one glaring major weakness in MVC in my view.

    The Views are basically a mixture of HTML & C# pseudo code with no separation! This is a throwback to the classic ASP days when HTML was mixed with server side code. Talk about spaghetti code!

    With Viewstate compression getting more advanced, increase in bandwidth getting ever greater and HTML5 controls on the way for Webforms, the webform model for me is the cleanest separation of HTML & server side "real" C# code.

    Another thing is the length of development time it takes to produce the same results. Developing in MVC takes way longer than WebForms.

  • For those who think that MVC is a step back because now you really have to know your stuff, I call lazyness. The framework appeard for a reason and to me there's no "choice", there's a bad way and a better way to develop websites. I wish there was a compiler for the HTML and the CSS so you know how it feels to be a real programmer. Read my article if you want to know how bad Web Form is in details.

    Great article, thanks

  • I'm one of those old school VB6 programmers that sorta had to move into ASP.Net in order to stay viable. I appreciate the abstraction that WebForms provides me so I get get to the business rules without worrying too much about the mechanics of the html. I understand the difference as explained in the blog, and fortunately I only write back-end administrative stuff and no public facing stuff. For me, personally, web forms is the way to go.

  • I've developed a few MVC apps, just to see what the fuss was about. Quite frankly, I still don't see what the fuss is about. I've been using dynamically generated HTML from code in web forms for what, 4 or 5 years now? It's much faster and less complicated to do it in web forms vs. MVC as well. Really. How hard is it to write HTML to a literal control....? This is not rocket science.

    The bottom line is that MVC cannot do anything that web forms couldn't already do and vice versa. MVC is just another way to make switching from other languages like PHP and Ruby less frustrating. It's not faster, it's not better. It's just a different way of doing the exact same thing.

    If you are using web forms and like them, stick with it. You're not missing out on anything.

  • Let's assume the technologies are equal. in both technologies and can say without a doubt, you have more options available off the shelf in asp.net than mvc.

    But through that out and assume they are equivalent. It TAKES 3-4 TIMES LONGER TO DEVELOP IN MVC to produce the same result in asp.net.

    End of argument. I have deadlines to meet and am very tired of wasting nights and weekends trying to meet a deadline with mvc.

  • Please give me link for tutorial

  • The commmon complaints I hear about web forms are.

    Problem:
    "Arrggh.. The viewstate!, it's too large!"
    Solution:
    You know, you don't actually have to use viewstate in webforms if you really don't want to right? And with the release of .NET 4 framework, it's been slimmed down even more.

    Problem:
    "MVC let's me use jQuery instead of the crappy ATLAS .NET framework easily"
    Solution:
    You don't have to use any of the built in AJAX stuff that comes with .NET, you can still use jQuery.

    Problem:
    "Webforms doesn't let me create valid HTML"
    Solution:
    Sure it does, i've had no issue validating all of my apps in HTML5 with a minor rewrite of certain controls.

    Problem:
    "But MVC is the way of the future!"
    Solution:
    The MVC pattern has been around for quite a long time, it's just been recently jazzed up by Microsoft. (more $$$ for Micro$oft)


    I was a front end developer for 5 years and recently moved into a back-end position and I have absolutely zero problems controlling the output of .NET controls, styling, and generally front end anything. Did I mention how much time webforms saves me so I can enjoy life? Too much of MVC is rebuilding the wheel and reminds me of an old classic ASP templated framework I used to use back in the day.

    I dunno, i'm still learning MVC in my off time, but i'm not seeing any redeeming qualities to it. In regards to testing, well, don't forget now that testing isn't automagical. It still relies on the dev creating the potential tests and use cases, always a margin for error here (Strictly QA'ing your own code is never a good idea). Your best "test" comes from an external QA department using and trying to break your application.

  • Just my thoughts...

    I've been using MVC 2 for the last 6 months on a 15 man dev project. When you start introducing lovely things like portable areas, 20+ project solution & TFS, Visual Studio starts to run a tad slow. I'm finding MVCs flexibility, for me, adds more levels of complexity which reduces productivity. Yes it adds unit testing, etc... but when do we always get chance to do this when the pressure is on?

    I've also found recruiting MVC developers can also prove difficult in the UK - no doubt this will pick up.

    I used to like classic ASP back in the day, I loved ASP.NET web forms - yes it has it's flaws, which can be overcome. Although I'm still not sold on the microsoft MVC framework.

    I'm looking at the Yii php framework at present, looks pretty quick to pick up & offers the whole MVC experience.

  • i found exactly what i want...thanks..such a nice explanation.

  • Testability of web forms is easily accomplished in a loosely coupled presentation layer that implements a clean MVP pattern. I've found the passive view MVP implementation very useful and testable and I have to admit that I do lean toward we forms because it is truly a RAD methdology and as mentioned by another responder bad developers will be bad developers regardless of any tools used. I strongly advocate understanding of patterns and adherence to proven practices above any specific development tool or methodology.

  • I think that ASP.NET MVC was produced only to meet today's requirements for software development over the web. I offen realize how fast technology evolves and how me as a human could keep up with languages and tools and frameworks and layers...so one man realised that some we should skip. Why really did we convert the request into classes and classes into html on the first place? Because the authoring tool required it? Because of OOP? I see that the web is too large to fit on servers only, so we are already programming on devices, SmartPhones Tablets, using Java and Javascript and jQuery and Ajax and more. One of them is the browser and it is the host (and a very capable one)...so we forget the 'runat=server' and go to the 'input type=' again because that is what they understand, that is what we should (ordered to) author. I find the LoadControl() feature of WebForms a typical of its power, but the single-reentrant form for all parts of the page - no matter how dynamically and robust have i created them, it's biggest problem. I 've created almost everything using WebForms but i have already said goodbye!

  • having done a lot of developpement in webforms, and a lot of framework creation, I assure you people that the exact same thing as MVC can be accomplished in WebForms. I developped custom MVC framework that integrated with web forms, AJAX frameworks that also integrated with web forms. This without ever, never using view state, nor session for state stockage (session was used only to hold critical information regarding the context of the application). All my apps were fast and low foot print.

    So I dont see why I should transit to MVC. I think its a matter of choice, if you want to start out your career using it, great, go ahead and do so, but the opposite is so true as well. Its only a matter of personal choice.

    For me webforms=flexibility, control, rapid developpement, easy maintenance (assuming you know what you're doing, aka:experience), low foot print and performance.

  • I finally tried MVC recently and was annoyed by all of the work required to maintain state. It's pretty easy to do separation of concerns with Web Forms too...just have the code behind call methods of other libraries.

  • Web Forms are based on the assumption that it's authoring team exposes a set of rules for the developer even by Control level, through functionality hidden under a base container and through an event driven programming style. The result of that design created to automate technical requirements, conclusively added only another layer of complexity between the environment and those two parts.

    Some common questions on Web Forms that do not have anything to do with programming skills could be: Why this event doesn't fire? Why i lose post back data when i bind after Load ? Why the script isn't embeeded (Ajax), why should i call LoadPostBackData again? Why my ViewStated Property doesn't exist on Init and when should i bind a repeater Control that is on a UserControl that is loaded dynamically on page's Init event? What about third party Controls?

    Ok,after all these years we have overcome that challenges, but to solve them we have been forced to follow certain rules of the author, so...say goodbye to the myth that Web Forms is a platform for all and you can write anything you want.

    Web Forms was and still is a custom implementation that you must extend, it doesn't rely on a certain pattern and just continues the idea of 'autonomous' forms. The initial benefits from reusability and endless rich UI, will become a weekness if you can not remember all members, events, techniques and functionality of every component you meet on every project, every year.

    In our days, SOA programming is certainly enforced, and web applications become more popular due to ease of access. So when those two meet, a more open concept for ex. async requests programming and partial rendering should be establised.
    Controls are easy replaced by HtmlHelpers in MVC (after all....soon all browsers (clients) will have their own set of input controls) and state is preserved easily with the model binding system or tailor-made autoretrieval methods anywhere inside the domain. Practical standards and techniques do the job on that!

    What are you afraid of, my Web Forms developer?

  • I have to agree with the above post, its taken me years to try and remember all the WebForms controls properties/methods & annoying issues etc... They are mostly not generic or similar so there can be annoying confusion & mixups. I dont think Webforms is RAD when there's such a deep learning curve.

    MVC is like a breath of fresh air to me, I love the control it gives me and when coupled up with jQuery and web services its pretty quick to develop with and far less prone to hours or even days trying to work out silly WebForm issues. Its almost like the RISC approach for microcontrollers that I spent time with, its so much quicker for me to develop with.

    That said, I will still using WebForms for certain projects, as I use WinForms every now and then instead of its mighty sibling WPF! (Sorry couldn't help it)

  • Which technology should a new developer pick asp.net MVC or asp.net Webform experience ?

  • I would say asp.net web form with smart use of Jquery (Javascript) will be better over MVC anytime!

  • Which technology should a new developer pick asp.net MVC or asp.net Webform experience ?

  • can anybody please tell me, can i make dynamic textbox's and label's in ASP.NET MVC3? if yes, then how?
    please tell me if anybody knows?

    THANKS

  • This article and comments (some of them) are of great help, and I am very grateful to the author for it, but I disagree with the author about being able to make SEO friendly pages only with ASP.NET MVC cause we can acheive the same using Directory names containing a default.aspx or default file.

  • This is a great article on understandings MVC.
    The rich webcontrol in WebForm is really attractive for quick project development.
    Definitely, controlling the size of ViewState is always a challenge and is difficult for the beginneer.

    However, i think that both MVC and WebForm developers will be exposed to browser compatibility issues, as long as the way in solving can vary.

  • I just like this website greatly, It is a very nice post to read and find information.

  • That's help me in understading difference between ASP.net MVC Vs ASP.net Web Form

  • very nice put up, i definitely love this website, keep on it

  • Nice article, but I want to know, does ASP.NET MVC3 supports dynamics text box's and labels?.

  • I just put the link of your blog on my Facebook Wall.
    very nice blog indeed.”-’,

  • So Useful Article for me !! Thanks a lot

  • Thank you for every other informative site. Where else may just I
    get that type of information written in such
    an ideal method? I have a undertaking that I am just
    now running on, and I have been at the look out for such info.

Comments have been disabled for this content.