Databases Reference
In-Depth Information
As you can see, all work in the UnleashedControl is done by its only method called
OnInit . In the base class, DynamicControl , this virtual method is responsible for finding an
appropriate field template and instantiating it inside of the dynamic control. This overrid-
den method performs the additional initialization steps before calling the inherited
version.
First, it checks to see if the Mode property is different from the default value ReadOnly ; you
do not want to silently overwrite the value specified by the developer in template markup.
If the mode has not been specified explicitly, the code probes the TemplateControl prop-
erty to find the parent entity template, an instance of the EntityTemplateUserControl
class. If the parent entity template was found, the code initializes the Mode property of the
dynamic control based on the Mode property of the parent entity template.
With the UnleashedControl and UnleashedLabel controls, you can modify the custom
multimode template for the Customer entity to look similar to what is shown in Listing
10.10. This new version no longer requires additional initialization logic in the code
behind and does not hardcode display names of the properties in template markup. At
this point, it has no plumbing that would unnecessarily obscure the intent of the
markup—it only contains logic defining the form layout and does not duplicate any infor-
mation from the entity metadata.
LISTING 10.10 Customer Entity Template with Extended Controls (Markup)
<%@ Control Language=”C#” CodeBehind=”Customers.ascx.cs”
Inherits=”WebApplication.DynamicData.EntityTemplates.CustomerEntityTemplate” %>
<unl:UnleashedLabel runat=”server” DataField=”CustomerID” />
<unl:UnleashedControl runat=”server” DataField=”CustomerID” />
<unl:UnleashedLabel runat=”server” DataField=”ContactName” />
<unl:UnleashedControl runat=”server” DataField=”ContactName” />
<fieldset>
<legend>Address</legend>
<unl:UnleashedLabel runat=”server” DataField=”Address” />
<unl:UnleashedControl runat=”server” DataField=”Address” />
<br />
<unl:UnleashedLabel runat=”server” DataField=”City” />
<unl:UnleashedControl runat=”server” DataField=”City” />
<unl:UnleashedLabel runat=”server” DataField=”Region” />
<unl:UnleashedControl runat=”server” DataField=”Region” />
<unl:UnleashedLabel runat=”server” DataField=”PostalCode” />
<unl:UnleashedControl runat=”server” DataField=”PostalCode” />
</fieldset>
 
Search WWH ::




Custom Search