Customizing ASP.NET Dynamic Data
ASP.NET Dynamic Data lets you customize the appearance and behavior of database entities in an application in the following ways:
Customizing general behavior. This type of customization applies to data entities independently of the database. You make these customizations in the presentation layer.
Customizing schema-specific behavior. This type of customization applies to entities in a specific database. You make these customizations in the data layer or in the presentation layer.
Customizing General Behavior
You can modify how Dynamic Data performs tasks that do not rely on a specific database schema. This can include tasks such as customizing the appearance and behavior of all the tables in the database, or customizing the appearance and behavior of data fields of a specific data type. You can then use these customizations for other projects. This type of customization lets you define consistent behavior for any data schema without having to redefine it every time that you add or modify a table.
You make these customizations in the presentation layer by modifying the default Dynamic Data templates. The customizations apply to the entire Web site, not just to a single data entity, and are independent of any specific database.
You can customize general behavior in the following ways:
Customize the default page templates. This is useful if you want to modify the List or Details view for the whole application.
Customize the default field templates. You can modify the appearance and behavior of data fields of a specific data type for the whole application.
Customize the default entity templates. This lets you customize the UI for a whole data entity such as a row or a table. This provides more flexibility than customizing individual data fields, and is useful if you want to create custom UI and apply it to default or custom page templates.
For more information, see ASP.NET Dynamic Data Presentation Layer Customization.
Customizing Schema-Specific Behavior
You can also customize Dynamic Data behavior for individual tables or data fields based on the data model or database schema. A typical customization is to create custom UI for an individual data field. Another example is to create a custom page to display and interact with a specific table.
You make these customizations in both the presentation layer and in the data layer. If needed, you can create custom templates. These customizations apply to specific data entities and depend on the specific database.
You can customize schema-specific behavior in the following ways:
Customize individual table layout. This is useful if you want to modify the page template to display and interact with a specific table, such as a custom Edit page template for only the Product table in a database.
Customize individual data field layout. You can create a custom field template in the presentation layer and associate it with a specific data field in the data layer.
Customize individual data field layout using default templates. Dynamic Data provides default templates for data fields (such as fields that contains e-mail and URL information) that you can associate with specific data fields whose database type is string or text.
Customize validation for an individual data field. To do this, you apply the attributes from the System.ComponentModel.DataAnnotations namespace to the fields in the data model. These attributes define common validation patterns, such as range checking and required fields. This approach lets you use predefined validation checks with very little coding.
Customize validation for individual data fields using custom validation attributes. This lets you extend the validation options that are provided by the System.ComponentModel.DataAnnotations attributes.
Customize validation for an individual data field by writing a method that processes changes for that data field (or by handling a corresponding event). This approach lets you add validation and business logic for an individual field, and lets you define complex validation logic.
Customize validation for any data field by overriding the OnValidate method (or handling the Validate event). This method (and event) is invoked whenever a change is made to any data field. This approach is more general than adding validation for an individual field. It is useful when the same validation logic can be applied to more than one data field. It also lets you perform validation checks that involve multiple fields.
Create custom table action links. Dynamic Data enables you to create dynamic hyperlinks that are based on the table actions that are enabled by Dynamic Data. When a user clicks a link, a page is displayed that enables the user to perform the action that is specified by the link, such as listing detail data rows or editing a data item.
To make schema-specific customizations, you can do the following:
Customize the data layer. This approach lets you perform custom validation of data fields and associate custom templates to tables or data fields in the data model. You use this approach to customize the behavior of an application as a whole. This means that the data field customization is used in any table that contains that field. You customize specific data fields by using the System.ComponentModel.DataAnnotations attributes. For example, you use the UIHintAttribute attribute to associate a custom template with a specific data field.
Customize the presentation layer. You can limit the customization of a specific data entity to a single custom page. This approach lets you perform custom validation and modify data field layouts in the page markup. For example, you can use the UIHint or UIHint properties to associate a custom template with a data field.
For more information, see ASP.NET Dynamic Data Layer Customization.