WebForms or MVC? What about the third option?

by Mads Kristensen 9. February 2009 20:44

I’ve read a lot of posts and articles about why and when you should choose WebForms or the MVC framework to build your ASP.NET websites. They are all pretty good, but for some reason they forget or ignore the obvious third option - standard ASP.NET without the WebForm.

Let’s call standard ASP.NET without a WebForm for ZeroForm. Basically, the ZeroForm approach is to use ASP.NET like you always have but without a <form runat="server"> element. I consider the ZeroForm as an excellent compromise between WebForms and MVC.

Server- and user controls

There are some immediate drawbacks from regular ASP.NET WebForms by not using the <form runat="server"> tag. A lot of the regular server controls like the TextBox, DropDownList and all the validators will not work. Other controls like the Repeater, PlaceHolder, custom user controls and all HtmlControls like <div runat="server"> will work as normal. Where WebForms support all the controls and the MVC framework none, this can be considered a good compromise.

ViewState and HTML markup

By getting rid of the WebForm, you are now in (almost) complete control of your markup. No ViewState, WebResource.axd’s and embedded JavaScript are injected in your pages anymore. The only thing that remains out of our control is the rendered ID’s of HTML elements. If you nest server- or user controls you still cannot control that until the release of .NET 4.0. Again, a fair compromise.

Pretty URLs

The MVC framework has a very cool way of creating pretty URLs using the new routing engine in .NET 3.5 SP1. You can use the routing engine with your WebForms and ZeroForms, but it isn’t really as fluent as in a MVC application. But hang on; URL rewriting has always been possible in ASP.NET so you could get the same pretty URLs by using ZeroForms. It does take some extra work but people have been doing it for years using various libraries or their own implementations. This is not a compromise, but the notion of that it's possible on both frameworks.

Separation of concerns

The MVC framework is the champ in separating concerns in your web application. No question about it. A lot of articles explain this very well, so I will not go into details. What haven’t been well explained is that by using the ZeroForm you can also separate a whole lot. Keep your model (custom objects) separate from the code-behind and your .aspx’s and .ascx’s as dumb as possible by leaving the code-behind to deal with data using utility classes or helpers that can be tested. This is nothing near the separation the MVC framework offers, but it is a good compromise.

This post is not meant to bash either WebForms or the MVC framework, but to offer an alternate view for your consideration. I’m a huge fan of WebForms, ZeroForms and the MVC framework and I use them all for different types of projects respectively.

An example of a website using the ZeroForm approach is ifjernsyn.dk (in Danish).

Tags: , ,

ASP.NET

Comments

2/9/2009 9:22:26 PM #

trackback

WebForms or MVC? What about the third option?

Thank you for submitting this cool story - Trackback from DotNetShoutout

DotNetShoutout |

2/9/2009 9:35:31 PM #

Kazi Manzur Rashid

I think it requires few correction:

>>>>Where WebForms support all the controls and the MVC framework none, this can be considered a good compromise.

The controls that has Postback does not behave same in ASP.NET MVC.

>>>>Pretty Url
You can use the new Routing in WebForm too as it is not ASP.NET MVC specific. Phil Haack has few working demo. So I guess no more Url rewriting in coming days.

>>>> Separation of concerns
It has nothing to do with ASP.NET MVC or Web Forms.It all depends upon the craftmanship. Nothing gonna stop you breaking the SOC in MVC. On the other hand you achive the complete SOC in Webform applying MVP.

>>ZeroForm
??

Kazi Manzur Rashid United States |

2/9/2009 9:41:45 PM #

awake

Might as well write the app in classic asp

awake United States |

2/9/2009 9:44:01 PM #

Mads Kristensen

@Kazi,

I agree with you totally. It's the online discussion about the pros and cons that I think is missing an important point - the compromise or simply just another approach to ASP.NET development.

@Awake,

I can't see why that is, in any way, the same as the ZeroForm...?

Mads Kristensen Denmark |

2/10/2009 2:44:48 AM #

Troy Goode

While Awake is ignoring the obvious benefits of having the .Net framework running behind everything rather than VBScript, he has a point that the technique you are describing essentially gives you Classic ASP + C#/VB.Net.

But is there anything wrong with that? I would suggest that if MVC/MonoRail and the like didn't exist - "ZeroForms" would be an approach worth considering due to the advantages over WebForms that you have listed. The real question is: if you are starting a new project today, why would you choose ZeroForms over MVC?

Troy Goode United States |

2/10/2009 5:00:35 AM #

Mac

There is much more behind the ZeroForms concept than what meets the eye: Scalability.

In ASP.net, if you use session state at all, your project becomes difficult to scale (that is a fact, ask the folks at myspace). If you use viewstate too much, the pages bloat. To scale, its best to avoid postbacks to the same page at all, turn off viewstate, and the ZeroForms approach addresses just that.

The web is still stateless, there are a lot of people (even inside MS) that seem to have tried to fix it and came up with many great solutions to give it state, using various tricks, hidden postback fields(asp/net) and whatnot.

All well and good, but this stuff doesn't scale well, still.
(think request and output caching, especially the squids - it's all URL based)

Getting a more of the state info into the URL and using that data in consequent requests to the server is a really good idea, no matter what flavor that comes in (MVC/Rails/etc.), I'm all for it.
--
Mac
Jobs and Services in Spain
www.trabajoXpress.es

Mac United States |

2/10/2009 12:46:55 PM #

ILog

Hi guys,

Seems, I don't understand the term "ZeroForms". Basically, the question is: do you use @Page directive in .aspx file or not? If yes, the overhead of Page object still exists. If not, we need to invent some markup generator for complex controls (i.e. something similar to server controls for WebForms). Otherwise, the productivity is low and it's not real alternative.

Actually, I tried to use .ashx in combination with NVelocity (which is great). But all the time I have a feeling of incompleteness of such a solution. It quickly becomes a big mess of objects, data, and markup.

Did anybody tried ZeroForms in real projects?

ILog Czech Republic |

2/10/2009 12:54:03 PM #

Mads Kristensen

@ILog,

The ZeroForm is still using the @Page directive and everything else except the <form runat="server"> element. I've done a mobile site using ZeroForms at http://ifjernsyn.dk

Mads Kristensen Denmark |

2/10/2009 4:14:50 PM #

pingback

Pingback from alvinashcraft.com

Dew Drop - February 10, 2009 | Alvin Ashcraft's Morning Dew

alvinashcraft.com |

2/10/2009 5:11:39 PM #

Marwan

what the MVC framework did is making the easy things more easier and cleaner

Marwan Tunisia |

2/10/2009 9:42:06 PM #

pingback

Pingback from arjansworld.com

Arjan`s World    » LINKBLOG for February 10, 2009

arjansworld.com |

2/11/2009 11:28:25 AM #

ILog

@Mads,

Thanks for the explanations. I see your point now.

ILog Czech Republic |

2/11/2009 12:58:52 PM #

Hans

The ifjernsyn.dk website is so plain simple that ASP.NET MVC would fit just fine. Why botter to coin a new term to develop a site like that. ZeroForms is WebForms, but may have a better performance, as many bloated things of WebForms is disabled - but it is still WebForms, and it will always be. SoC is the main argument for moving away from this technology.

Hans Denmark |

2/11/2009 1:54:35 PM #

Mads Kristensen

@Hans,

Yes, the ifjernsyn.dk site is very simple because it's a mobile site. The reason I didn't use MVC was because I didn't want to write the extra code needed and because I didn't care about testability and SoC that much. It's a hobby site. However, since it's a mobile site, I cared deeply about the markup, so I wouldn't use WebForms. Therefore I chose the compromise that I call ZeroForms in lack of a better term.

There's nothing new about it and that was sort of my point.

Mads Kristensen Denmark |

2/12/2009 2:38:59 PM #

trackback

WebForms or MVC? What about the third option?

You've been kicked (a good thing) - Trackback from DotNetKicks.com

DotNetKicks.com |

2/12/2009 3:01:41 PM #

Dennis Knappe

My man Smile

I often use that approach to, very nice for small apps.

/Dennis

http://builder.dk

Dennis Knappe Denmark |

2/12/2009 4:53:54 PM #

trackback

WebForms or MVC? What about the third option?

You are voted (great) - Trackback from Web Development Community

Web Development Community |

2/12/2009 7:29:05 PM #

AdvanCode

I'd call it 'no server-side form', not ZeroForm. I'm using this technique on a website mainly because it's very AJAX-loaded (JQuery + Ajax Control Toolkit), so viewstate or postbacks doesn't help us at all.

Good thing is that HTMLControls with runat=server works just fine from code behind as you said.

AdvanCode Canada |

2/12/2009 10:29:11 PM #

Gregory Kornblum

I think any application with an interface should use whatever form framework provided. The whole point of it is to get more done in a shorter time-frame. All this MVC/formless methods are nothing but a step backwards. First it's lets through out forms and now its lets throw out datatypes.

If you were to build a C# Windows application with an interface would you create it without making any use of a forms designer? You could but unless you don't mind doubling or tripling the turn around time and make yourself look bad to higher ups it is pointless. RAD is an evolution, all this non-sense using 30 year old methods such as MVC is simply the exact opposite of the evelution software development has made.

I'm sure your thinking, hey this guy is nuts but why do you think things like form designers were made in the first place? Because it makes things better for developers and the companies they work for.

Gregory Kornblum United States |

2/12/2009 10:56:18 PM #

mike johnson

hmmm. i thought the "obvious" third option was to combine MVC & WinForms. That said, I think your notes about whats there are just as valid.

mike johnson Canada |

2/13/2009 2:11:00 AM #

trackback

WebForms or MVC? What about the third option?

DotNetBurner.com - news and articles about .net DotNetBurner

WebForms or MVC? What about the third option? - DotNetBurner |

2/13/2009 3:19:00 AM #

Mark


I have just completed an app with the "zeroforms" approach, however I would call it the multi-form approach.

I choose not use the form@server so I could build my pages with multiple forms on a single page.

The multiple forms approach, allows you to build your actual pages quickly, each page already has a url to it... I didn't care about url for this app.

I love mvc, but when I started the project mvc just wasn't ready..

Go Multiform!

Mark Australia |

2/13/2009 4:26:58 AM #

leo

blog.gadodia.net/.../
choosing between webform and asp.net mvc

leo People's Republic of China |

2/13/2009 8:35:42 AM #

Dennis Knappe

> Gregory Kornblum: MVC i definitely not at step back - but quite the opposite. I think you can build an ASP.NET MVC application, at least as fast as a webform, more clean, more in control, and more testable.

Play ASP.NET webforms by it's own rules, can be a pain, especially when more complex control is needed. I would go for MVC or ZeroForms..

Dennis Knappe Denmark |

2/13/2009 4:06:52 PM #

ILog

@AdvanCode,

I called such an approach NoWebForms, but I like Mads' "ZeroForms" much more. So, trademarked to Mads Smile

ILog Czech Republic |

2/13/2009 11:35:04 PM #

cowgaR

<i>Where WebForms support all the controls and the MVC framework none, this can be considered a good compromise.</i>

I stopped reading, pointless article...

MVC supports quite a few webforms controls (the most complex being MS Chart one) and look on Telerik (the most infamous control builder) and its collection of MVC ready controls...

I can't imagine walking in the company as an architect and "putting on the table" your approach, more to it that we now have MVC avaiable which is simply supperior to webforms/zeroforms whether you like it or not.

cowgaR United Kingdom |

2/14/2009 5:30:18 PM #

Trevro

By cutting out MVC, you are just creating more work for yourself.  Using MVC is similar to what you already are doing.  It's just that you will have to build the infrastructure yourself every time you start a new website.  So why not use MVC.  I don't see a downside.

Trevro United States |

2/16/2009 10:59:06 AM #

Adron

I gotta go with MVC.  That's my 2 cents.

Adron United States |

2/17/2009 1:52:09 AM #

Tim

I wouldn't completely ignore MVP (WCSF).  I've recently begun working with it in earnest and do like it very much - even more than MVC.  I also fail to see what the issue is with webforms - outside of less then 20k of JS downloaded, I have yet to find a situation where I cannot ensure the outputed HTML is not to my satisfaction.

An internal web application isn't go to die over an extra 20k of information "cached" on a persons machine - and using callbacks instead of postbacks with (perhaps) some custom controls negates my need to ever even learn MVC.

I know HTML/CSS and Javascript *very* well, but for quite a few developers, webforms is awesome - why take it away for the sake of the few (comparitively speaking) that can truly handle the complexities of what it takes to virtually duplicate what webforms does for you?

Certainly my opinion - but I (almost) always go with what can be supported after I am gone from a contract...

Tim United States |

2/17/2009 1:54:12 AM #

Tim

Sorry - quick note... I disable Viewstate always and use session as well, but scaled to SQL usually...  all controls are custom and heavily rely on ajax (raw or JQuery/both)

Tim United States |

2/18/2009 2:29:00 PM #

trackback

ASP.Net: WebForms oder MVC? Was ist mit der dritten Option?

ASP.Net: WebForms oder MVC? Was ist mit der dritten Option?

www.babblr.de |

2/24/2009 1:50:19 PM #

pingback

Pingback from blog.dmbcllc.com

ASP.NET MVC - Is The Grass Really Greener?

blog.dmbcllc.com |

3/3/2009 10:44:12 AM #

Blogger Inspiration

Play ASP.NET webforms by it's own rules, can be a pain, especially when more complex control is needed. I would go for MVC or ZeroForms..

Blogger Inspiration United States |

3/20/2009 3:49:15 PM #

Gadgets in Future

like Webform

    * does Postback (which adds unnecessary more than 20 kb of  javascript )
    * has Viewstate (performance issue)
    * has to go through whole page life cycle
    * Uses Event based model

which are stuffs built by microsoft guys to simplify development for VB 6 User which are really not required to make a great site, although i appreciate those thing because it  helps in rapid development.

Gadgets in Future United States |

3/23/2009 11:19:41 PM #

awake

OMG...

I start using ASP.NET MVC today and it's bringing back scary memories of classic ASP.  

I have nothing against it, but if I'm going to go the MVC route on any project...  I probably be using an Open Source solution (Yii Framework) preferably.

awake United States |

4/23/2009 12:22:48 PM #

pingback

Pingback from pimp.webproasp.com

Web Pro ASP - Active Server Page Development News

pimp.webproasp.com |

4/26/2009 4:39:55 PM #

alex

This .net mvc framework is really ggod

alex United States |

4/26/2009 4:40:38 PM #

alex

wheere can i find some training tutorial to this mvc framework?

alex United States |

8/25/2009 4:54:23 AM #

pingback

Pingback from topsy.com

Twitter Trackbacks for
        
        WebForms or MVC? What about the third option?
        [madskristensen.net]
        on Topsy.com

topsy.com |

9/2/2009 11:42:25 AM #

pingback

Pingback from trentjones.net

MVC, WebForms, ZeroForms | Trent Jones

trentjones.net |

Comments are closed

About the slave

Mads Kristensen Mads Kristensen
Web developer at ZYB and founder of BlogEngine.NET. More...

LinkedIn ZYB Facebook Last.fm Twitter View Mads Kristensen's profile on Technorati

The Lounge

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008