Databases Reference
In-Depth Information
because it produces concrete UI elements for specific entity types as opposed to abstract
templates that can handle any entity type.
It is ironic that when faced with the choice of implementation approach, most ASP.NET
developers new to Dynamic Data tend to err on the side of metadata and neglect the use
of templates. We can only speculate as to why this tendency exists. Metadata indeed plays
an important role in Dynamic Data applications. For some tasks, such as specifying
display names of entity types and their properties, the use of data annotation attributes is
required. When you know that field labels can be specified in the metadata, it seems
logical to specify the order of fields on the form in the metadata as well, even though the
form layout has nothing to do with the business logic and it could be easily implemented
with custom entity or page templates. Continuing this line of thought leads you down the
path of trying to use metadata to control all presentation aspects of all entities.
This and subsequent chapters discuss common challenges that arise in real-world web
application projects and how they can be addressed with Dynamic Data components. This
chapter starts with concrete, template-based solutions that are easier to understand and
implement. Chapter 11, “Building Dynamic Forms,” shows how these specific solutions
can be generalized to take advantage of metadata and generate user interface dynamically.
Multimode Entity Templates
As discussed in Chapter 4, “Entity Templates,” entity templates are primarily responsible
for implementing form layouts. Out of the box, Dynamic Data provides dynamic entity
templates for displaying entities as a single column of labels and controls in Read-only,
Insert, and Edit modes. Dynamic Data also allows you to define custom templates that are
not limited to the single-column layout.
Custom Templates
Listing 10.1 shows the markup of the custom Edit mode entity template,
Customers_Edit.ascx , created for the Customer entity type in Chapter 4, Instead of a
single column of labels and controls, this entity template relies on the HTML fieldset
control to group the address fields together, with the customer ID and name displayed
above it. Another template, Customers.ascx , replicates the same Customer form layout in
Read-only mode. If you were to compare the markup for these two custom templates, the
only difference between them is the Mode attribute of the DynamicControl instances they
use. The Edit-mode entity template sets it to Edit , and the read-only entity template
leaves it as ReadOnly .
LISTING 10.1 Edit-Mode Customer Entity Template (Markup)
<%@ Control Language=”C#” CodeBehind=”Customers_Edit.ascx.cs”
Inherits=”WebApplication.DynamicData.EntityTemplates.CustomerEditEntityTemplate”%>
 
 
Search WWH ::




Custom Search