Databases Reference
In-Depth Information
Label label = (Label)sender;
label.Text = this.currentColumn.DisplayName;
}
protected void Label_PreRender(object sender, EventArgs e)
{
Label label = (Label)sender;
DynamicControl dynamicControl =
(DynamicControl)label.FindControl(“dynamicControl”);
FieldTemplateUserControl fieldTemplate =
dynamicControl.FieldTemplate as FieldTemplateUserControl;
if (fieldTemplate != null && fieldTemplate.DataControl != null)
{
label.AssociatedControlID =
fieldTemplate.DataControl.GetUniqueIDRelativeTo(label);
}
}
protected void DynamicControl_Init(object sender, EventArgs e)
{
DynamicControl dynamicControl = (DynamicControl)sender;
dynamicControl.DataField = this.currentColumn.Name;
dynamicControl.Mode = this.Mode;
}
}
}
As you can see, the only change needed is to make in the original Edit mode dynamic
template to support multiple modes is add a single line to initializing the Mode property of
the DynamicControl instances programmatically, based on the Mode property provided by
the EntityTemplateUserControl base class. Everything else in the code-behind was already
in place.
Now that there is only one dynamic multimode template, Dynamic Data uses the custom
entity template, Customers.ascx , in Edit mode before falling back to the dynamic
template, Default.ascx . This allows you to implement custom form layouts in a single
place by implementing multimode entity templates. However, this approach still allows
you to build mode-specific templates, such as Customers_Edit.ascx , in case you need to
fine-tune the appearance of the entity form in different modes.
Creating Dynamic Label Control
There is one flaw in this last implementation of the custom multimode entity template,
Customers.ascx : Display names of the columns are hard-coded in the markup of the
template. This presents a problem because the same display names also must be specified
in the entity metadata for the validation error messages that can be displayed to the users
 
Search WWH ::




Custom Search