The next version of ASP.NET Webforms

05 Mar
March 5, 2011

Webforms is still alive and well

ASP.NET MVC has been getting a lot of attention recently as the new framework from Microsoft that attempts to match the capabilities of some of the other competing technologies such as Ruby on Rails – however the vast majority of ASP.NET projects are still written in Webforms.

As a result, the Microsoft ASP.NET team haven’t been ignoring Webforms, despite a perception in the development community that MVC is going to be the preferred framework in the future.  In fact, ASP.NET 4.0 included a number of updates to Webforms that incorporated many of the features that make MVC so compelling such as URL Routing, reduced ViewState, and greater control of the HTML mark-up produced by many ASP.NET controls.

The constant updates to MVC (now up to version 3) leave the feeling that interest from Microsoft in Webforms has stalled, however unlike MVC, the Webforms assemblies and types are in the .NET framework base class library itself, so changes to Webforms need to be included in a major ASP.NET release, rather than being added ‘out of band’ like MVC.

That said, the next major release of ASP.NET will include some pretty cool advances for those developing in Webforms.

MVC ModelBinders

Both Webforms and MVC are smaller frameworks that sit on the ASP.NET foundation framework and give you choice in how you choose to build your application.

In the MVC framework. there is the concept of a “ModelBinder”.   In MVC you use some code to access data to generate a Model to build a View.  When the View requests user input, the ModelBinder is the entity that takes that input and feeds it back into the Model.   The ModelBinder is basically code that sits in the middle tier and performs model management with the user input.

In Webforms, today if you want to use a data control like the Gridview or Listview, you typically add a Gridview control to a page, and also add a corresponding ObjectDataSource.  You then configure the Gridview to use that ObjectDataSource and then create another class that the ObjectDataSource is going to look at  which then has code in it which contains the methods that take in user inputs (Create, Update, Delete).  These methods are then added to the ObjectDataSource as parameters.  This code creates a lot of HTML markup, and is quite difficult to test as these methods are tied into the ASP.NET base classes which are difficult to separate.

The next version of Webforms will considerably simplify the process so that rather than having the ObjectDataSource on the page, the data controls such as the Gridview or Listview can be pointed directly into the class methods that handle your user input.  So when a user updates a record, the values in that record are automatically bound to the correct method.

This will significantly cut down on a lot of code generation, as well as making the code much easier to test.

Improvements in Validation

The next version of Webforms will include the unobtrusive validation currently shipping with MVC.  Today in Webforms, you have server side validator controls that can be added to a page and linked to an input field such as a textbox that give you validation facilities.  But there is a large amount of Javascript created in the underlying html to do the client side validation.  The new version of Webforms will clean this up by using the same mechanism as MVC, which uses jquery.validate to provide the client side validation base framework, then use HTML 5 Data-custom attributes to inject the metadata required to drive that validation into the page directly onto the controls that you want to validate.  This will significantly reduce and simplify the underlying mark-up that is generated on your page.

CSS Sprites

CSS sprites are a new technique in CSS that will be supported in the next release of ASP.NET Webforms.  A CSS sprite is a single file that contains all the images used on your page, laid out in a grid.  Downloading a single large image rather than multiple small images is more efficient as it only requires a single server call.  Historically, best practice was to ‘slice’ each image to make pages load faster – however each one of those images is a separate HTTP Request, and bandwidth is a lot more plentiful now than in the past.

According to “Performance Research, Part 1: What the 80/20 Rule Tells Us about Reducing HTTP Requests” by Tenni Theurer on the Yahoo! User Interface Blog,

Popular web sites spend between 5% and 38% of the time downloading the HTML document. The other 62% to 95% of the time is spent making HTTP requests to fetch all the components in that HTML document (i.e. images, scripts, and stylesheets). The impact of having many components in the page is exacerbated by the fact that browsers download only two or four components in parallel per hostname, depending on the HTTP version of the response and the user’s browser. Our experience shows that reducing the number of HTTP requests has the biggest impact on reducing response time and is often the easiest performance improvement to make.

Conclusion

Microsoft are still significantly investing in ASP.NET Webforms, incorporating the best from the Webforms and MVC frameworks into the base ASP.NET classes, based on feedback received from customers, developers, and their internal teams.  MVC and Webforms are both excellent frameworks – neither is ‘better’, but each are more suited to different scenario’s.  The future release of ASP.NET is still in development, and will incorporate more features from MVC into Webforms than described here.   However, the improvements detailed in this post should ease any worries you may have as to whether Webforms is suitable for your next ASP.NET project.

Tags:
© Copyright - Evonet