Databases Reference
In-Depth Information
LISTING 10.21 Continued
}
protected override void OnInit(EventArgs e)
{
if (this.Mode == DataBoundControlMode.ReadOnly)
{
EntityTemplateUserControl entityTemplate =
this.TemplateControl as EntityTemplateUserControl;
if (entityTemplate != null)
{
this.Mode = entityTemplate.Mode;
this.ValidationGroup = entityTemplate.ValidationGroup;
}
}
base.OnInit(e);
var eventHandler = (EventHandler)this.Events[FieldValueChangedEvent];
if (eventHandler != null)
this.FieldTemplate.FieldValueChanged += eventHandler;
}
}
}
In the built-in DynamicControl class, the FieldTemplate property returns an object of type
Control . The UnleashedControl redefines this property to return a strongly typed instance
of the UnleashedFieldTemplate class. This helps to reduce the amount of typecasting in
this class as well as in entity templates that need to access the field templates directly.
The FieldValue property provides a convenient way of getting and setting the FieldValue
property of the underlying field template programmatically. It is not intended to be used
from markup.
The FieldValueChanged event is also a convenience wrapper. It can be used to assign
event handlers for the field template's FieldValueChanged event. Unlike the FieldValue
property, this event is intended for use in markup, although it can be used programmati-
cally as well. To support assigning event handlers from markup, when the field template
has not been instantiated yet, the event handlers are stored in the Events list of the
UnleashedControl itself. When the field template has been created in the OnInit method,
the event handlers, if any, are assigned to the field template's own event.
 
Search WWH ::




Custom Search