Databases Reference
In-Depth Information
The CustomValidator control in this field template performs the job you would normally
expect the DataTypeAttribute to do. Even though DataTypeAttribute inherits from the
ValidationAttribute class, it does not actually perform any validation. Its IsValid
method always returns true , which is why the DateTime_Edit template uses the
CustomValidator control to ensure that the value entered by the user matches the type
specified by the DataTypeAttribute . The SetUpCustomValidator method enables the
validator if the column was marked with a DataTypeAttribute and the
DateValidator_ServerValidate method performs the actual validation.
LISTING 3.6 DateTime_Edit Field Template (Code-Behind)
using System;
using System.Collections.Specialized;
using System.ComponentModel.DataAnnotations;
using System.Web;
using System.Web.DynamicData;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication.DynamicData.FieldTemplates
{
public partial class DateTime_EditField : FieldTemplateUserControl
{
private static DataTypeAttribute DefaultDateAttribute =
new DataTypeAttribute(DataType.DateTime);
public override Control DataControl
{
get { return this.textBox; }
}
protected void Page_Load(object sender, EventArgs e)
{
this.textBox.ToolTip = this.Column.Description;
this.SetUpValidator(this.requiredFieldValidator);
this.SetUpValidator(this.regularExpressionValidator);
this.SetUpValidator(this.dynamicValidator);
this.SetUpCustomValidator(this.dateValidator);
}
protected override void ExtractValues(IOrderedDictionary dictionary)
{
dictionary[Column.Name] = this.ConvertEditedValue(this.textBox.Text);
}
 
Search WWH ::




Custom Search