Databases Reference
In-Depth Information
this.SetAttribute(p.Key, p.Value.ToString());
}
}
Notice that you cannot implement this logic directly in the overridden OnInit method of
the UnleashedControl . On one hand, you do not know which entity property this control
represents before the inherited OnInit method is called because the Init event handler in
the dynamic entity template has not had a chance to initialize the DataField property
yet. On the other hand, after the inherited OnInit method is finished, the field template
has already been created, and calling the SetAttribute method will have no effect. To
solve this problem, the custom attributes are set in the InitializeControlParameters
method. This method is added as the last handler to the Init event, which fires at the
appropriate moment—after the initialization code in the dynamic entity templates but
before the field template is created.
Although implementing initialization of field template parameters in the UnleashedControl
is a little more involved, it offers a better encapsulation and allows you to simplify the
implementation of the default entity template. This becomes more important as you begin
implementing additional dynamic entity templates later in this chapter. Consider the final
version of the Default.ascx entity template in Listing 11.4.
LISTING 11.4 Final Version of Default Entity Template (Markup)
<%@ Control Language=”C#” CodeBehind=”Default.ascx.cs”
Inherits=”WebApplication.DynamicData.EntityTemplates.DefaultEntityTemplate” %>
<table class=”DDDetailsTable”>
<asp:EntityTemplate runat=”server” ID=”entityTemplate”>
<ItemTemplate>
<tr>
<td class=”DDLightHeader”>
<unl:UnleashedLabel runat=”server” OnInit=”Label_Init” />
</td>
<td>
<unl:UnleashedControl runat=”server” OnInit=”DynamicControl_Init” />
</td>
</tr>
</ItemTemplate>
</asp:EntityTemplate>
</table>
Because the UnleashedControl and UnleashedLabel (also introduced in Chapter 10)
controls are designed to work with minimum configuration in both custom and dynamic
entity templates, you only need to initialize their respective DataField properties with the
name of the entity property for which the controls are being generated. The controls
Search WWH ::




Custom Search