Asp.Net Controls vs. View Components

During my Monorail talk a lot of people were asking about whether or not you could use Asp.Net controls with Monorail. I think the question translates to I love my 3rd party web controls yet I hate ASP.Net enough to look into alternatives. I think we need a clean break here.

Can you do it? 

The answer is… sort of. First, you need to be using the Asp WebForms view engine.

After reading the documentation and seeing comments like:

With WebForms you can use all your existing skills to develop MonoRail applications, however its integration with MonoRail can be quite tricky

Let’s take a look at an example of perfectly decent controller code and explain when it does not integrate with WebForms.

So, many simple scenarios can get really hard with WebForms.

You will likely back away slowly and start scratching your head.

Your mileage may vary as I know little about using Asp WebForms in Monorail as is container in the docs.

The trouble with harry

Asp.Net is based on a leaky abstraction that layers a stateful control model over a stateless protocol. To solve the state problem they bring viewstate into the picture to bridge the gap by serializing the entire state of a page’s control tree within the page itself. It is a bit like embedding a continuation within the view so that your controller (aspx) knows how to populate its own state. As a side-effect when the page gets complex the viewstate gets big and starts hogging bandwidth. Viewstate is usually the first thing you abandon once your .aspx page gets significantly complicated. Additionally, if you are creating your own server controls viewstate related bugs have likely haunted you at one time or another.

Thoughts from the O’sphere

Better people than I have already discussed the merrits of Monorail vs Asp.Net Webforms with controls:

View Components

If you want the benefit of ASP.Net control like reusability in Monorail you need to look into using View Components (docs).

Ayende as always has some great posts:

Jason Meridth sent me a link to JoeyDotNet’s posts on monorail which has a few posts regarding view components I am sure will be useful:

Do you know a Guy?

If you know of other ViewComponents resources out there or want to share your view components with me. Send me a line. I want to see the ASP.Net alternative seeking, Monorail evaluating, 3rd party controls junkies out there get hooked up with a source for the drop-in View Component love they are seeking.