Databases Reference
In-Depth Information
uses the custom attribute values to set the public properties defined by the field template
class, like the
Columns
property defined by the
Text_Edit
field template. Figure 11.7 shows
how the Address text box, dynamically configured by this code, is now much wider than
text boxes for other string properties.
FIGURE 11.7
Address TextBox with Columns parameter.
Extending Dynamic Data to Support Control Parameters
Although the current solution allows you to continue evolving the Employee form with
metadata, at some point, you might need to create a custom entity or page template. In a
custom template, having to specify the
Init
event handler for every
DynamicControl
instance becomes a nuisance you would rather avoid. You also have a problem with the
dynamic list pages that display data with the help of
GridView
control because it does not
offer an easy way to access the
DynamicControl
instances.
This section shows how the Dynamic Data controls can be extended to implement consis-
tent support for metadata-driven control parameters.
Extending DynamicControl to Support Control Parameters
The
UnleashedControl
was introduced in Chapter 10 to encapsulate some of the func-
tionality necessary to implement field template interaction. You can further extend it to
support control parameters. Here is an extract from
UnleashedControl.cs
(without the
rest of the implementation reviewed in Chapter 10, which is not relevant to this discus-
sion):
protected override void OnInit(EventArgs e)
{
// ...
this.Init += this.InitializeControlParameters;
base.OnInit(e);
// ...
}
private void InitializeControlParameters(object sender, EventArgs args)
{
MetaColumn column = this.Column ?? this.Table.GetColumn(this.DataField);
var hint = column.Attributes.OfType<UIHintAttribute>().FirstOrDefault();
if (hint != null)
{
foreach (KeyValuePair<string, object> p in hint.ControlParameters)