Roundup of ASP.NET Dynamic Data

Dynamic Data is a very nice tool comes with .NET 3.5 SP1. It offers CRUD support out of box (scaffolding) and is also very easy to customize!

Add to an existing web applicataion: for many web applications (especially those existing LOB apps), using Dynamic Data on backend admin pages is probably the most common use of it. MSDN has an article here to cover the steps to add Dynamic Data to your existing ASP.NET app.  It worked perfected for me. This article also tells you how to add Dynamic Data to a sub-folder.

Another trick on securing the \DynamicData folder is to add <authorization> policies in web.config file for\DynamicData folder.

http://www.asp.net has a good video series about Dynamic Data. Below are my roundups of the main knowledge points, and the things I learned after playing with it:

  • URL routing: “List|Details|Edit|Insert” and ListDetails.aspx can co-exist. No need to comment one out.  Enabling both of them allows the app to support both ways ( separate page editing or in-place editing) – all determined by the way you request the page.  Actually I think this is better.
  • CustomPages: just create a folder under it named after the plural format of the table name (Products).
  • ScaffoldAllTables = false: for security reasons this should be turned off.  However for any table you want to scaffold you have to do one of these 2 things
    • extend the table class and decorate it with [ScaffoldTable(true)]
    • create custom pages in \CustomPages folder
  • Validation:
    • Declarative: [Required] [Range(0, 2000)]
    • Imperative: extend those partial OnXXX event handlers, and throw Exceptions with error message.
  • Hide a column from scaffolding: [ScaffoldColumn(false)]
  • Change display: [DisplayFormat(DataFormatString = “{0:yyyy-MM-dd}”)]
  • Customized edit control: [UIHint(“ReadOnly”)], then in \FieldTemplates folder, add a ReadOnly_Edit.ascx
Advertisements
This entry was posted in ASP.NET and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s