Putting ASP.NET Dynamic Data into Context
There's a lot of folks excited about ASP.NET MVC as an option for creating ASP.NET websites. As I say in my ASP.NET MVC talks, however, I figure about 5% of people creating ASP.NET sites will care about ASP.NET MVC. I say that for a number of reasons. ASP.NET MVC is a big paradigm shift. It enables the developer to make a more testable site, to have absolute control over their markup, and to separate concerns in order to keep their code DRY (don't repeat yourself). However, MVC is not yet the ideal solution, in my opinion, for really data- and forms-heavy sites. Creating an data grid with editing in place with sorting, movable columns and all that coolness is hard in MVC as someone needs to manage all that state for you and there's some underlying infrastructure that's not there.
So, What about the other 95% of developers? Certainly WebForms isn't going away, and it is a proven solution for line of business apps. Personally, I'll probably use some kind of hybrid as I have in the past at other jobs. DasBlog doesn't use MVC (yet) but it's templating system is MVC-like and it lives side-by-side with WebForms. Basically, there's a lot of WebForms developers out there just trying to get data up into a Grid or Edit view and also keep it DRY.
You'll probably stumble onto information around ASP.NET Dynamic in your wanderings and I wanted to give you some information to put Dynamic Data's pending release into ASP.NET's larger context.
What is ASP.NET Dynamic Data?
Here's the Preview Drop of Dynamic Data for download. It'll be released later this year in a future Service Pack for .NET Framework 3.5. This is a pre-release build that's updated since the relatively quiet preview release last December.
Fundamentally, Dynamic data is new controls for DetailsView, FormView, GridView, or ListView controls along with a lot of meta-infrastructure classes to make it possible. The design uses convention over configuration in a number of places, and this marks, IMHO, the recognition of a simpler way to do things.
If you can point at one thing in Dynamic Data and say, "that's it!", it'd be DynamicControl. it's a control that takes metadata from your Database model (LINQ to SQL or LINQ to Entities in v1, other POCOs (Plain Old CLR Objects) or ORM's possibly in v.Next) and selects from a FieldTemplateUserControl.
Stated differently, if you've got a field in a dozen places that should show Phone Numbers, you probably want a Textbox, some validators, maybe a MaskedEditControl, or perhaps some 3rd party controls. You think about it as a Phone Number. if you decide to change that control, you want to change it for the whole application. You want to keep it DRY (Don't Repeat Yourself). Currently, unless you had the discipline to create a PhoneNumberUserControl, you'd have to do "monkey work" and go find all the instances of that field and keep them up to date. You'll be repeating yourself all over with data that should exist in one place, like the length of the field in the database, gets copied into possibly dozens of places, validators, controls, etc.
Here's a comment that my friend Peter Blum left on ScottGu's Blog. It actually was Peter, not the Product Team, who helped me "grok" Dynamic Data a few weeks ago. We spent a few hours on the phone talking and it finally popped for me.
I have been working with Dynamic Data for over a month and am very excited about it. I wanted promote an aspect of Dynamic Data that will be used in many other situations than the application Scott showed.
Dynamic Data introduces a new web control called DynamicControl. It can be used in FormView and ListView controls to provide a UI based on database-level schema. When using GridView and DetailsView, you add a DynamicField, which is a replacement for the BoundField that internally has a DynamicControl. (Thus has all of the features of a DynamicControl.)
This results in your Grids and data entry forms being built around tables and columns of your database with whatever smart data entry controls you like, such as the AJAX Control Toolkit's MaskedTextBoxExtender on a textbox or your favorite third party controls. The database schema also determines the validators for this column. That avoids errors implementing the right validators or updating them when the database schema is modified. (No more "how do I validate a BoundField?" issues!)
To me, Dynamic Data is a major step forward in developing data entry oriented web applications for ASP.NET.
One of the demo's that is often shown is Dynamic Data's "scaffolding" feature. Basically, you point the wizard at a database and "poof" you've got a nice DataGrid Admin-like site. However, to dismiss it as a scaffolding tool is just the mistake I made when I first saw it.
How does it work?
There's a LOT of cool plumbing to Dynamic Data and I'll try to work with the team to get a podcast or two done and some articles explaining the deep how. Here's the basic how.
You can make a new Dynamic Data Website and it looks pretty much the same as any other site, because it is. It's a WebForms site just like any others, except for a new folder, called DynamicData. That folder has a web.config of its own to block access. This is the convention. Let's open it up.
Let's say I want some serious customization. Let's so that the page for the Products table should be TOTALLY custom, but just the ListDetails page. I'll put that under /CustomPages. Let's say I want to use a Telerik control for DateTimes, Integers, and TextAreas, but just some of them.
Nothing HAS to look the way it comes by default. Everything is customizable. If I want grid paging to look like whatever i want, I change the GridViewPager.ascx. You can customize at the Table, Column and DataType level.
I can put "hints" on a metadata-specific class like this:
[Range(0, 100)]
[UIHint("IntegerTelerik")]
public object UnitsOnOrder { get; set; }
That UIHint will be used later when I hook up a DynamicControl. As soon as DynamicData sees I'm bound to the UnitsOnOrder column, it'll automatically find IntegerTelerick_Edit - based on the naming and location convention - when it needs to show the "Edit" state. I can set it on a pull column basis, and then I can change it everywhere from one place.
Here's what that ASCX looks like in code:
<%@ Control Language="C#" Inherits="System.Web.DynamicData.FieldTemplateUserControl" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Linq" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e) {
var metadata = MetadataAttributes.OfType<System.ComponentModel.DataAnnotations.RangeAttribute>().FirstOrDefault();
if (metadata != null) {
RadSlider1.MinimumValue = (int)metadata.Minimum;
RadSlider1.MaximumValue = (int)metadata.Maximum;
}
}
protected override void ExtractValues(IOrderedDictionary dictionary) {
dictionary[Column.Name] = ConvertEditedValue(RadSlider1.Value.ToString());
}
</script>
<telerik:RadSlider ID="RadSlider1" runat="server" Value="<%# (short)FieldValue %>" />
See how it's generic (by that I mean non-specific, not CLR Generic)? I've replaced the Textbox that is usually used for an Integer and am using a Telerik Slider. The [Range] attribute can be pulled off and popped into this instance of the control.
Here it is at runtime, next to some other Integer columns:
Now, I get to think about selecting the correct DataType via UIHint rather than using the ASCX directly. It makes the control really reusable within the context of data binding and keeps me from repeating myself.
I can add Validation Controls to a data type, so the Validation exists in one place, rather than repeated all over. For example, if you wanted to swap out validation for one, or all, your controls, to use Peter's Validation and More (which rocks, by the way, we bought a site license at my last job) than you'd do it once per data type.
This is just one VERY simple example, but it's, I think, I pretty good one. Thanks to Scott Hunter for helping me out with this as well as my talk at Devscovery last week. There are some good Dynamic Data samples he's done that you can download and check out. One includes a "before and after" application that shows how an address book would be coded using the new DynamicControl and the older way (using BoundControl).
An even cooler (and advanced) example is one where Scott Hunter wants to pull an funky binary encoded image out of an old database. He makes a custom control that handles a custom data type called "DbImage" and completely encapsulates the display of that column. From the point of view of the GridView, it's just a DynamicControl that shows itself as an <img> tag.
Sheesh, ASP.NET is changing too fast, this is too much to absorb
This is a big deal to me because it's going to make a subset of my work easier. If I've got a database and I don't mind using LINQ to SQL or LINQ to Entities (for now), I'll be able to create CRUD (Create, Read, Update, Delete) websites WAY faster.
Projects with Dynamic Data will be more customizable than those "typical Microsoft demos" where someone drags a DataSource and GridView over to the Design Surface, shows you a list of Products from Northwind then waits for applause. ;)
Why is this NOT a big deal? Everything you are used to still works as before. This is additive and simple if you just want to avoid repeating yourself.
Why is it on Code Gallery?
You might notice that this pre-release drop is on MSDN Code Gallery, that's a temporary thing to get your feedback. It'll eventually find a home on http://www.asp.net as it's ultimately part of the larger ASP.NET framework.
Here's a diagram that we've used internally to decide where to put stuff. Consider this drop to be a "showcase" ;) as it'll only be up for a little while. If you have issues, bugs, opinions on Dynamic Data, go put them in the Issue Tracker as the team is watching closely!

Note: This Dynamic Data project at Code Gallery is a very temporary home for ASP.NET Dynamic Data in order to gather feedback. When ASP.NET Dynamic Data appears in an 'official' release, we will remove the release from this site and redirect you to the new 'official' release.
Should you Fear This Release?
It's a pre-release build, but it's pretty harmless. It does install a few Project Templates in VS, but it shouldn't screw up your VS install. If you are using ASP.NET MVC, be aware that this drop includes a version of the ASP.NET Routing. This will be reconciled when they all are released, but for now, be aware of your version numbers.
"This release includes the Dynamic Data runtime assemblies as well as versions of the System.Web.dll and System.Web.Extensions.dll assemblies that have been updated from the versions in the .NET Framework 3.5. The release also installs Visual Basic and C# templates that you can use in Visual Studio 2008 for creating a Dynamic Data Web site."
These updated DLLs will be GAC'ed, and there's a batch file for installing and uninstalling. The changes are largely additive, but if you're deeply risk-adverse, use a VM. The batch file will make it clear what's changing on your system and what's not. Be aware there's a different batch file for 64-bit vs. 32-bit systems. This will all be automatic in the final release as it'll be rolled into the .NET Framework.
Dynamic Data in a Nutshell
If you're using Data Binding and any of the DetailsView, FormView, GridView, or ListView controls to do CRUD, consider using Dynamic Data, especially if you're using the BoundColumn. It will save you time and trouble.
In the future, watch for the possibility of Dynamic Data for POCO (my term, not the teams), Dynamic Data for Silverlight and Dynamic Data for MVC. Now is your opportunity to be heard. I'd like the idea of Dynamic Data for NHibernate myself, so I'm pushing for that. Feel free to engage in the Dynamic Data Forums or post bugs on this release in the issue tracker.
Related Links
- Dynamic Data wizard walkthrough on WebDevTools
- David Ebbo's Mix talk on Dynamic Data
- ScottGu's Announcement of Dynamic Data
- Scott Hunter's Screencast on Dynamic Data (WMV)
About Scott
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.
About Newsletter

Monster 4 Outlet Mini Power Strip








My wife and I have been 



