Databases Reference
In-Depth Information
LISTING 10.17 Extended Text_Edit Field Template (Markup)
<%@ Control Language=”C#” CodeBehind=”Text_Edit.ascx.cs”
Inherits=”WebApplication.DynamicData.FieldTemplates.TextEditField” %>
<asp:TextBox ID=”textBox” runat=”server” Text='<%# FieldValueEditString %>'
AutoPostBack=”<%# AutoPostBack %>” Columns=”<%# Columns %>”
OnTextChanged=”TextBox_TextChanged”/>
<asp:RequiredFieldValidator runat=”server” ID=”requiredFieldValidator”
ControlToValidate=”textBox” Enabled=”false” />
<asp:RegularExpressionValidator runat=”server” ID=”regularExpressionValidator”
ControlToValidate=”textBox” Enabled=”false” />
<asp:DynamicValidator runat=”server” ID=”dynamicValidator”
ControlToValidate=”textBox” />
Changing Field Template's Base Class
As the base class of the field template is specified in its code-behind file (Listing 10.18),
you need to change it from the built-in FieldTemplateUserControl to the new
UnleashedFieldTemplate .
Setting Data Control's AutoPostBack Property
The Text_Edit field template uses a TextBox as its data control. The easiest way to
initialize its AutoPostBack property is with an ASP.NET data binding expression,
<%# AutoPostBack #> , in template's markup file, as was shown in Listing 10.15. This
expression is evaluated during the data binding stage when the page is first generated.
It assigns the value of the AutoPostBack property provided by the base class,
UnleashedFieldTemplate , to the AutoPostBack property of the TextBox control.
Raising the FieldValueChanged Event
The TextBox control used by the Text_Edit field template offers a TextChanged event,
which you can use to detect when a user changes its value. In template markup, the
TextBox_TextChanged method is assigned as an event handler. Its implementation, shown
in Listing 10.18, simply calls the OnFieldValueChanged method inherited from the
UnleashedFieldTemplate to raise the FieldValueChanged event.
LISTING 10.18 Extended Text_Edit Field Template (Code-Behind)
using System;
using System.Collections.Specialized;
using System.Web.UI;
namespace WebApplication.DynamicData.FieldTemplates
{
public partial class Text_EditField : UnleashedFieldTemplate
{
 
Search WWH ::




Custom Search