Databases Reference
In-Depth Information
FieldValueChanged Event
The
OnFieldValueChanged
method is responsible for invoking the
FieldValueChanged
event handlers, if any have been assigned, when the
FieldValue
property changes.
Following the standard .NET event implementation pattern, this method is declared as
virtual. This allows the descendants to handle the event by overriding the method, which
is more efficient than assigning an event handler.
NOTE
The
FieldValueChanged
event explicitly defines the
add
and
remove
blocks to take
advantage of the
Events
collection inherited from the ASP.NET
Control
class. This
collection is optimized for storing infrequently assigned event handlers and allows you
to store event handlers in a hash table instead taking space for each event in every
instance of the control. The
FieldValueChangedEvent
object is used as a hash key to
store and retrieve the
FieldValueChanged
event handlers, if any.
AutoPostBack Property
The
AutoPostBack
property of the field template encapsulates the
AutoPostBack
property
of the data entry controls. Consumers, such as the custom
Region
field template, typically
set it when they need to receive immediate notifications about field value changes.
Unfortunately, ASP.NET controls do not have a common base class that would allow
setting their
AutoPostBack
property generically. The individual field templates are
responsible for initializing their data controls based on this property.
Extending Existing Field Templates
To take advantage of the better encapsulation offered by the new
UnleashedFieldTemplate
base class, you need to implement the following changes in each of the existing field
templates:
.
Change the field template to inherit from the
UnleashedFieldTemplate
class.
.
Set data control's
AutoPostBack
property value with the value from the
AutoPostBack
property of the field template.
.
Raise the
FieldValueChanged
event when data control's value changes.
.
Update data control's value when
FieldValue
changes.
With the exception of the last one, these tasks are what the original version of the
Region_Edit
field template had hard-coded. By implementing these changes, you are
encapsulating this logic inside of each general-purpose field template and allowing the
custom field template to access the information without taking dependencies on the inter-
nal implementation details of other templates. Listings 10.17 and 10.18 show the markup
and code-behind of the
Text_Edit
field template that has already been extended. The
changes (indicated by bold font) are discussed through the remainder of this section.