Databases Reference
In-Depth Information
<label>ID:</label>
<asp:DynamicControl runat=”server” DataField=”CustomerID” Mode=”Edit” />
<label>Name:</label>
<asp:DynamicControl runat=”server” DataField=”ContactName” Mode=”Edit” />
<fieldset><legend>Address</legend>
<label>Street:</label>
<asp:DynamicControl runat=”server” DataField=”Address” Mode=”Edit” /><br />
<label>City:</label>
<asp:DynamicControl runat=”server” DataField=”City” Mode=”Edit” />
<label>State:</label>
<asp:DynamicControl runat=”server” DataField=”Region” Mode=”Edit” />
<label>Zip:</label>
<asp:DynamicControl runat=”server” DataField=”PostalCode” Mode=”Edit” />
</fieldset>
This way of implementing a custom form layout is not ideal. Each of the two custom
templates recreates the same layout, essentially duplicating the implementation and
increasing the cost of ongoing maintenance. Though this might not be a big deal for a
template as simple as the one in this example, the problem becomes more and more
apparent as the complexity and the number of the custom entity templates grows.
Because in this and a majority of other scenarios the Mode of the DynamicControl instances
match the mode of the entity template itself, you could set it programmatically, inside of
the Init event handler for individual controls. This would allow the Customers entity
template to support all three modes—Read-only, Edit, and Insert—making the
Customers_Edit.ascx entity template unnecessary. Listing 10.2 shows the new version of
this multimode entity template.
LISTING 10.2 Multimode Customer Entity Template (Markup)
<%@ Control Language=”C#” CodeBehind=”Customers.ascx.cs”
Inherits=”WebApplication.DynamicData.EntityTemplates.CustomerEntityTemplate” %>
<label>ID:</label>
<asp:DynamicControl runat=”server” DataField=”CustomerID”
OnInit=”DynamicControl_Init” />
<label>Name:</label>
<asp:DynamicControl runat=”server” DataField=”ContactName”
OnInit=”DynamicControl_Init” />
<fieldset><legend>Address</legend>
<label>Street:</label>
<asp:DynamicControl runat=”server” DataField=”Address”
OnInit=”DynamicControl_Init” /><br />
<label>City:</label>
<asp:DynamicControl runat=”server” DataField=”City”
OnInit=”DynamicControl_Init” />
Search WWH ::




Custom Search