The post could equally be about me, given my lack of content recently, but clients, lack of time and general apathy all play their part. However, what I really want to say is mostly explained by the title, that of the future of WebForms, in particular that they have a future. A lot of what we read in blogs, articles, etc is MVC related and that’s fair; it’s still relatively new to the ASP.NET arena, and new and shiny always gets press; WebForms had lots of coverage when it was released – it was “A Big Thing”. Those that blog and speak at conferences and user groups tend to be the ones passionate about their technology, the vocal few who believe strongly, and it’s easy to get sucked into the new technology vortex, the belief that what they are saying applies to every project you are on.

Recently on a mailing list I’m on, there’s been a thread about MVC versus WebForms. Lots of good arguments and one exceedingly well constructed message from someone important; I hope it gets blogged because it will go a long way to quell the fears that many have, that WebForms is a dying technology. It’s not. It’s still being actively developed (the WebForms and MVC teams are about the same size) and still plays an important part in Microsoft’s web strategy.

The thing is, there are good and bad points for both frameworks and which one you use depends on many factors: the project requirements, available skills, etc. Here’s my take.

MVC

Advantages

  • Complete control over UI. With no server control framework you can construct exactly what you want, how you want, making it easier to use script frameworks.
  • Great for Test Driven Design. The separation between components makes TDD much easier. It doesn’t solve all your TDD problems, but it does make them easier.

Disadvantages

  • More UI work. Since you don’t have a rich set of controls, you have to create your UI yourself, although there are helpers to, well, help.
  • Learning curve. While MVC isn’t hard to learn, it’s very different from WebForms, so don’t think you can just jump in.

WebForms

Advantages

  • Maturity. It’s a well established, stable framework. Don’t confuse older with superseded.
  • Control framework. The rich set of controls make pulling together a UI very quick. That can have disadvantages, but if you know what you’re doing the UI can be almost as clean as an MVC one.
  • Postback and ViewState. Yes they are hacks on top of HTTP and can cause many issues, but they work very well for what they were designed for. The event based lifecycle is very easy to understand, especially for beginners.

Disdvantages

  • ViewState. The defaults produce more ViewState than is really necessary, leading to larger pages.
  • Test Driven Development can be hard, especially testing UI code. Abstracting as much code out of code-behind files can help, but you’re still bound to the postback architecture.

That’s just my top picks, there are plenty of other points worthy of mention. I’m a big fan of WebForms, but that doesn’t mean I don’t like MVC too. Bits of MVC I don’t like, in particular the standard view engine (I’ve never really liked inline <%%> code , even in ASP and ASP.NET WebForms, but that’s a personal thing), so I’d probably use Spark View instead. The one thing I’ve said right from the very first previews of MVC is that it needs some form of control architecture; not server controls, because remember, there’s no page lifecycle, but controls to abstract the common rendering; some people, including myself, find the <%%> hard to read, while a declarative control is easier. I doubt a control framework will appear when the helpers work so well, hence my preference for another view engine, which is another advantage – better pluggability. I like the controller architecture, and routing (oh, and routing is supported in WebForms too).

It’s also important to remember that not every project has the same requirements. Two projects I work on are WebForms, mainly because they predate MVC, but even if they didn’t, I’d still use WebForms. Why? Well they are both Intranet/Extranet applications, low numbers of users; one has lots of data editing via forms, the other less so, but still enough that WebForms and the UpdatePanel (yes, I use the UpdatePanel) work perfectly well. Page size and rendering performance aren’t an issue in these applications (and considering that one of them uses databases with 30-50 million rows of data; rendering is a minor issue compared to database performance).

And furthermore, both MVC and WebForms are just a part of ASP.NET; remember all the services (membership, roles, etc), providers, and so on, that are fully supported by both frameworks. ASP.NET 4.0 improves WebForms and although the changes look small, they have an important impact on the framework. Just because WebForms isn’t evolving at the same rate as MVC, doesn’t mean it’s been forgotten. WebForms doesn’t need to evolve so fast.

Scott Hanselman did a blog post on Dynamic Data, which is a good read in itself, but at the bottom there are a bunch of links to WebForm resources. Some may talk about MVC, but there’s still plenty of movement on the WeForm front.