ASP.NET 4.0 and Visual Studio 2010 Enhancements

Visual Studio 2010

Visual Studio 2010 will feature expanded snippets available in the HTML editor window. These snippets will dramatically change the way you write ASPX markup. For instance, if you were to add a TextBox to the page as soon as you begin typing <asp:TextBox... the snippet will take over and add in the ID and runat attribute.

Further, consider adding a RequiredFieldValidator to the page and the amount of work required in the past to properly configure the control. With the new snippets if you add a validator directly next to the TextBox you created previously, the snippet will automatically fill out the markup for the control, populating the ControlToValidate attribute, add the id and runat attributes and position your cursor inside the ErrorMessage attribute. Hand-coding has never been so easy!

Note: You’ll never have to type runat="server" again!

Further enhancements include the ability to triple-click an expansive element like a table and the editor selects the entire table’s markup. Want to surround that table with some additional markup? Just start typing with the table selected and your markup is inserted around the selected code.

ASP.NET Innovation

The ASP.NET platform has enjoyed a number of out-of-band updates in the form of AJAX, Dynamic Data and MVC, but the core of WebForms has remained without an update for a while. The reason is that the core of WebForms is dependent on System.Web, which is loaded by IIS.

This limitation has the attention of the ASP.NET team and in the future they are looking for ways to ship out-of-band releases on the core of WebForms. Until then we wait for the official release of ASP.NET 4.0 which will include the follow updates to WebForms:

  • Control of Control IDs: ASP.NET developers will finally have total control over the ClientID that is rendered to the page for each control. For simple scenarios you simply provide the ID value and in a data-bound context you can provide the key and replacement tag. For instance if you have a control in a data-bound control and you want the key to be "lbl" then the controls will have IDs consistent with lbl1, lbl2, lbl3 and so on.

    Scott Galloway has an excellent post on the upcoming client ID changes: Way too much information on Control IDs and ASP.NET 4.0 Client Id Enhancements
  • Humble ViewState: Programming on the web often requires storing state somewhere. Using session state is prone to timeouts and can create problems in a server farm/garden environment. Many times the best place to persist data is in the HTML document itself. This logic is what drove the ASP.NET team to first implement ViewState, but an eager implementation (requiring parent controls to enable ViewState and other requirements) created bloated pages with unnecessary ViewState shoved up to the client.

    The next generation of ViewState allows for granular control over which controls require ViewState. The default template for "4.0" project may even have ViewState turned off by default.
  • Dynamic Image Support: ASP.NET will feature rich image support giving developers an easy way to manipulate and maintain images on the web. Features include an image handler base class that is responsible for converting byte arrays to images and back again. A server control that calls the handler and helps pass parameters for uniquely identifying image data as well as stamping for cache support. The cache may be configured to cache on the server, the client or in both locations. Images are manipulated by a set of transforms which include resizing and watermarking among others.
  • IQueryable BusinessLogicDataSource: This new data source will feature query blocks which expose a declarative LINQ syntax to help create dynamic where clauses to append to search queries. The SearchExpression query block allows you to easily add "starts with", "ends with" and "contains" type of constraints to a query. The RangeExpression will read minimum and maximum values to constrain the range of a field. The LINQ syntax is generated when the page data binds sends the fully-constrained to the query to the server once all the parameters are known. Attributes associated with methods on the business logic layer will tell the data source which methods to run to select, insert, update and delete objects. The data source will work against a provider to interface with Linq to SQL, Linq to Enties, POCOs and more.

Dynamic Data

The Dynamic Data updates are spread among solutions for WebForms as well as MVC. Really the term "Dynamic Data" does injustice to the features as really they are becoming simply features of existing and new controls which are really just ASP.NET data controls.

For what you think of today as Dynamic Data, expect to see further work in the following areas:

  • Entity Templates: Much like a field template, but more of a container for markup and DynamicControls which can provide templating for an entire row of data rather than a single field.
  • Database Inheritance: Provide scaffold pages that will recognize database inheritance and provide CRUD capabilities for these tables.
  • Many to Many Relationships: Scaffolding will render check box lists to allow selection of many to many related data. (David Ebbo writes about this new feature in: A ‘Many To Many’ field template for Dynamic Data)

Use the Dynamic Control in a non-List Scenario?

The team is working on strategies for using the DynamicControl in situations where you are displaying a single record (and are outside the context of a list control).

Today a single record would bind to the FormView which supports the DynamicControl. Unfortunately FormView renders as a table in order provide places to hook in CSS classes. The FormView will soon feature a mode where you can turn off markup rendering all together so only the markup you provide is rendered.

There is talk among Scott and his team of the creation of an ItemView which may be a more natural fit for this type of scenario to compliment the ListView control.

Dyanmic Data & MVC

Out of respect of the culture surrounding MVC the team has chosen to implement Dynamic Data support backward to MVC. They began with adding HTML helpers and implementations for field/entity templates and databinding logic, leaving scaffolding for the end. This will ensure that Dynamic Data will work under MVC for those who choose to opt out of the scaffolding features.

In a seemingly controversial move, the team is implementing a version of ViewState for MVC! While the implementation details differ from traditional ViewState found in WebForms the technique of state persistence in a hidden HTML element will find its way to MVC.

In the interview, Scott poses the question of how one might implement optimistic concurrency in an MVC application. You may choose to implement a time stamp field or set aside the previous values for later comparison. If you choose to review old values then the state of this object must persist somewhere. So the team is looking to support developers who may choose a number of different approaches to the same problem.

Future Dynamic Data implementations for MVC will feature a controller with virtual methods for insert, update and delete. Using virtual methods obviously means that developers will have the option to over-ride and replace any methods they see fit.

Resources

Anonymous