When to favor ASP.NET WebForms over MVC
I know that Microsoft has said
ASP.NET MVC is not a replacement for WebForms.
And some developers say WebForms is faster to develop on than MVC. But I believe speed of coding comes down to comfort level with the technology so I don't want any answers in that vein.
Given that ASP.NET MVC gives a developer more control over their application, why isn't WebForms considered obsolete? Alternatively, when should I favor WebForms over MVC for new development?
As a Java "observer" from the outside, I'm very interested in this answer as well.
@Darknight :\ that's highly biased and simply wrong. MVC is not for simple CRUD apps. I'd argue WebForms is for generic CRUD apps (i.e. database -> some shiny grid control).
@Darknight You obviously have a poor understanding of MVC if this is your opinion... There are some huge sites built with mvc... do some research sir.
I'm not one to speak so this is just my opinion. After reading most of the answers I came to conclusion that the answer is just never. MVC is just awesome and the only drawback I found is that I keep seeing `;` at my webpage (If you're just beginning with Razor you'll get the joke).
@Darknight you know this is an ASP.NET MVC site? The MVC pattern is one of the best things to happen to web development in a longtime Ruby On Rails (Twitter) (Base Camp) Java's Spring framework, to many PHP examples to even count.
The problem is when a pattern is turned into a framework, that's my problem with asp.net MVC. You can use the same pattern and approach in web forms without the MVC framework. Since I originally commented (man this thread is old!) I've moved away from both frameworks. Its now mostly light services with pure ajax front end think SOA that I like :)
Lets put it this way, if you are building a house web forms are predefined construction modules and mvc are bricks. If you can make it happen using modules great, but usually you have to use bricks at some point. I would suggest go with MVC, always. Learning curve is actually not that bad.
I will just let go Webforms. MVC is the way to go. The main problem of Webform is Code behind , Code behind and Code behind. Below is a detail article which discusses the evils of code behind. http://www.codeproject.com/Articles/821275/Webforms-vs-MVC-and-Why-MVC-is-better
In reality, you don't go with something obsolete. If you go and find a job, you will notice less and less webform jobs. This is another reason why that you want to go with MVC.
@Darknight "The problem is when a pattern is turned into a framework" Why would that be a problem? Or on the flip-side - how could you have any framework without basing it on some core architectural pattern?
"When to favor ASP.NET WebForms over MVC" - Never. Anyway, it's all about OWIN, Web API and SPA's these days.
I'm seeing rumblings that `System.Web` is too difficult to maintain and that feature releases for WebForms will be slower than they were in the past. Microsoft is pretty consistently stating that WebForms support isn't ending any time soon, but don't expect WebForms to offer the latest and greatest features. E.g., Microsoft promotes vNext has having near-realtime code updates, but I don't think you'll get this with WebForms. WebForms won't be dead any time soon...but I'd be hesitant to use it for new projects.
I continue prefer asp.net for enterprise and intranet aplicativos and use mvc for small things and public websites
Q: When to favor ASP.NET WebForms over MVC? A: When you have already handed in your resignation, hate your current employer and coworkers, and want to leave them a nasty farewell present.
@MasterMastic "MVC is just awesome and the only drawback I found is that I keep seeing ; at my webpage (If you're just beginning with Razor you'll get the joke)." - I'm on my second day of using Razor, and anything ASP related....and I don't get the joke. Can you explain please?
Thinking about it, MVC is not a endgoal in itself something out of 2005, MS never intended to end up with it, now they rather see ASP as a modular framework, and in compliance with that, they evolved further their new kid in town is Kortana apps, apps that are no longer bound to IIS, but can run on linux servers as well, even android. I think its time to move on, and if possible skip older technology. From how i see kortana its less jinglebells more close to raw goal as ASP used to be.
Webforms vs. MVC seems to be a hot topic right now. Everyone I know touts MVC to be the next great thing. From my slight dabblings in it, it seems ok, but no I don't think it will be the end of webforms.
My reasoning, and the reasoning as to why webforms would be chosen over MVC, has more to do with a business perspective rather than what one is better than the other.
Time/money are the greatest reasons why webforms would be chosen over MVC.
If most of your team knows webforms, and you don't have the time to get them up to speed on MVC, the code that will be produced may not be quality. Learning the basics of MVC then jumping in and doing that complex page that you need to do are very different things. The learning curve is high so you need to factor that into your budget.
If you have a large website written all in webforms, you might be more inclined to make any new pages in webforms so that you don't have two very different types of pages in your site.
I'm not saying it's an all or nothing approach here, but it does make your code harder to maintain if there is a split of both, especially if not everyone on the team is familiar with MVC.
My company recently did three test pages with MVC. We sat down and designed them out. One issue we ran into is that most of our screens have the View and Edit functionality on the same page. We ended up needing more than one form on the page. No biggy, except then we wouldn't use our masterpage. We had to revamp that so that both the webforms pages and MVC pages could use the same masterpage for common look and feel. Now we have an extra layer of nesting.
We needed to create a whole new folder structure for these pages so that it followed the proper MVC separation.
I felt there were too many files for 3 pages, but that is my personal opinion.
In my opinion, you would choose webforms over MVC if you don't have the time/money to invest in updating your site to use MVC. If you do a half arsed approach to this, it won't be any better than the webforms you have now. Worse, you could even be setting this technology up for failure in your company if it's messed up, as upper management might see it as something inferior to what they know.
This is a good answer. I gave you +1 because your personal experiences are appreciated. But, this is failure due to a lack of experience/skill-set of the developers which I asked to avoid. I am not convinced that Microsoft would choose not to mark a technology obsolete simply because of a fear of the learning curve for MVC. This may be the case, but I'm not yet convinced.
@P.Brian.Mackey - I didn't say that forms development is faster than MVC. You asked to leave that argument out of it. Arguing time and money to train your staff is a different argument. MS won't mark webforms obsolete for one big reason: Enterprise clients have spent years developing web clients in webforms and won't look kindly on having to invest time and money to update.
@Tyanna if you knew both equally well and were working on a new project, then what would be the reasons to favour webforms?
@Raynos - If everyone on the team was proficient in MVC, and your company was starting a new project, then the only reason I could see someone choosing webforms is personal choice.
I know both technologies intimately. All my web projects are done with mvc and work at a company where I have free reign to do whatever is the best approach. I always chooose MVC.
@Tyanna Sad as it is, I think Microsoft do not care that much about their customers, specially developers. They dropped .Net Compact Framework completelly in mobile development with Windows Phone 7, in favor of Silverlight, 90% incompatible with .NetCF.
I started with Webforms and once I discovered MVC I switched to that. I don't know how anyone could defend webforms. Page lifecycle and one form for the entire page? Are you kidding me? Yahoo sitebuilder was probably the intended customer for it but even they didn't want that junk.
Never choose webforms over mvc. You will spend twice as much time in order to fix webforms shortages, then to create a proper mvc page.
@CokoBWare - that's great. This answer is 5 years old. Even still, WebForms isn't going anywhere. Just as people still support VB6 applications, legacy WebForms sites will live on.
@Tyanna yes, I am aware of that. But there are people that are still new to ASP.NET MVC who might come into older MVC versions that may not realize that WebForms in the new ASP.NET Core ecosystem effectively dead, and there is no plan to transition any WebForms code to the new hotness. WebForms will live on as legacy, just like ASP Classic lives on as legacy.
Anybody choosing webforms for new projects in 2017 is drastically limiting their options and their talent pool. Web-centric developers despise webforms. It's mere presence in DNN is a constant source of pain at my current job. We just had a problem in FF 52 where webforms decided it didn't like Firefox's version of parseInt and replaces it with its own version that THROWS FREAKING ERRORS rather than returning NaN or numbers when given non-strings. And since this process was asynchronous our short term solution required littering our codebase with `window.parseInt = Number.parseInt`. Not cool.
As someone mentioned above if most of what your applicaiton does is CRUD then webforms would take less time to develop with all existing control libraries and not having to care much about client-side coding, markup and maintaining state because webforms take care of this for you. But if you need something custom outside CRUD and public-facing then you may run into problems getting the exact behavior you need and with performance.
Also if you have an existing webforms app and then need a new sister app that will have similar functionality doing it with MVC may be a very bad idea becasue then when you're asked to replicate something from the webforms site on the MVC site it's a complete UI re-write and a pain to maintain both then.
If moving away from webforms I would consider switching directly to a client-side framework like Angular bypassing MVC. With MVC you get a mix of client-side and server side code, e.g. you may need to render the same markup on the server side and modify it on the client side later, which is inconvinient and makes things complicated IMO.