Databases Reference
In-Depth Information
LISTING 3.11 PhoneNumber_Edit Field Template (Markup)
<%@ Control Language=”C#” CodeBehind=”PhoneNumber_Edit.ascx.cs”
Inherits=”WebApplication.DynamicData.FieldTemplates.PhoneNumberEditField” %>
<asp:TextBox ID=”textBox” runat=”server” Text='<%# FieldValueEditString %>'/>
<ajax:FilteredTextBoxExtender TargetControlID=”textBox” runat=”server”
FilterType=”Custom” ValidChars=”+()-1234567890” />
<asp:RequiredFieldValidator runat=”server” ID=”requiredFieldValidator”
ControlToValidate=”textBox” Enabled=”false” />
<asp:RegularExpressionValidator runat=”server” ID=”regularExpressionValidator”
ControlToValidate=”textBox” />
<asp:DynamicValidator runat=”server” ID=”dynamicValidator”
ControlToValidate=”textBox” />
As you can see, the PhoneNumber_Edit field template is similar to the DateTime template
discussed earlier. It has a TextBox control used to enter the phone number, a
FilteredTextBoxExtender , another AJAX control used to prevent users from entering
symbols that would not be valid in a phone number, as well as several validator controls.
Although having a single DynamicValidator control is sufficient to enforce all validation
attributes applied to the column in the data model, this control performs validation only
on the server side, which requires a post-back before the error can be reported. Other
ASP.NET validation controls, such as the RequiredFieldValidator , are optional, but
because they also offer client-side validation logic, it's best to include them in field
templates to provide immediate feedback to the user, and improve the data entry experi-
ence.
Listing 3.12 shows the code-behind of the PhoneNumber_Edit field template.
LISTING 3.12
PhoneNumber_Edit Field Template (Code-Behind)
using System;
using System.Collections.Specialized;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.DynamicData;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication.DynamicData.FieldTemplates
{
public partial class PhoneNumberEditField : FieldTemplateUserControl
{
public override Control DataControl
{
Search WWH ::




Custom Search