Databases Reference
In-Depth Information
The resulting web page rendered at runtime is shown in Figure 1.9.
FIGURE 1.9
Data entry form with field templates.
Field templates are nothing more than a special type of user controls, which should be
familiar to most WebForms developers. Listing 1.7 shows the Integer_Edit field template
after a minor cleanup to improve readability.
LISTING 1.7
Integer_Edit Field Template (Markup)
<%@ Control Language=”C#” CodeBehind=”Integer_Edit.ascx.cs”
Inherits=”WebApplication.DynamicData.FieldTemplates.Integer_EditField” %>
<asp:TextBox ID=”textBox” runat=”server” Text=”<%# FieldValueEditString %>” />
<asp:RequiredFieldValidator runat=”server” ID=”requiredFieldValidator”
ControlToValidate=”textBox” Enabled=”false” />
<asp:CompareValidator runat=”server” ID=”compareValidator”
ControlToValidate=”textBox” Operator=”DataTypeCheck” Type=”Integer” />
<asp:RegularExpressionValidator runat=”server” ID=”regularExpressionValidator”
ControlToValidate=”textBox” Enabled=”false” />
<asp:RangeValidator runat=”server” ID=”rangeValidator”
ControlToValidate=”textBox” Type=”Integer” Enabled=”false”
EnableClientScript=”true” MinimumValue=”0” MaximumValue=”100” />
<asp:DynamicValidator runat=”server” ID=”dynamicValidator”
ControlToValidate=”textBox” Display=”Static” />
As you can see, it has a TextBox control for entering the field value and a
CompareValidator to prevent users from typing alphabetic symbols. This is similar to the
markup you would normally write by hand to validate the UnitsInStock values. However,
in the field template, all controls are initialized in the code-behind shown in Listing 1.8
based on the metadata information describing the column.
 
Search WWH ::




Custom Search