Databases Reference
In-Depth Information
Control Mode
Control mode
defines the context where the field template will be used. It can be one of
the members of the ASP.NET
DataBoundControlMode
enumeration:
.
ReadOnly
templates are used by the
Details.aspx
page template or custom pages to
display field values in Read-only mode.
.
Edit
templates are used by the
Edit.aspx
page template or custom pages to change
field values of an existing row.
.
Insert
are used by the
Insert.aspx
page template or custom pages to collect field
values for a new row.
When looking for a
ReadOnly
field template for the ShippedDate column of the Order
table, which has
DateTime
data type and no additional metadata attributes in the sample
data model, Dynamic Data finds the
DateTime.ascx
template.
Edit
mode is considered
more specific because it requires the field template to not only display the current field
value, but also allow changing it. Therefore, when looking for an Edit field template for
the ShippedDate column, Dynamic Data chooses the template called
DateTime_Edit.ascx
if it exists. Note that Dynamic Data uses the
“_Edit”
suffix for Edit templates and no
suffix for the
ReadOnly
templates. The Insert mode is even more specific because it might
require special logic to deal with rows that have not been submitted to the database, and
Dynamic Data chooses the template called
DateTime_Insert.ascx
if it exists.
Mode Fallback
If there is no matching field template for a particular control mode, Dynamic Data uses
fallback logic to find another template for a more generic mode. In this ongoing example,
when looking for an Insert template for the ShippedDate column, Dynamic Data will first
try to find the template called
DateTime_Insert.ascx
. Because there is no field template
with this name, it falls back from the Insert to the Edit mode and ends up using the
template called
DateTime_Edit.ascx
, assuming it can handle both Edit and Insert modes.
Similarly, if an Edit mode template cannot be found, Dynamic Data falls back to Read-
only mode.
However, before Dynamic Data falls back to the next
mode
, it performs the
type
fallback.
Consider UnitsInStock, an Int16 column from the Products table. When looking for an
Edit template for this field, it tries using
System.Int16_Edit.ascx
and
Int16_Edit.ascx
templates first, but because they do not exist, it falls back to type
Int32
and checks for
System.Int32_Edit.ascx
and
Int32_Edit.ascx
and eventually finds
Integer_Edit.ascx
.
If Dynamic Data performed the mode fallback first, it would skip this template and try to
look for a ReadOnly template called
System.Int16.ascx
instead.