Databases Reference
In-Depth Information
In field templates, the
DynamicValidator
controls are associated with
MetaColumn
objects
describing specific entity properties. However, the
DynamicValidator
control used by the
Edit page template is not associated with any particular column and specifies the
FormView
as its
ControlToValidate
. When configured this way, the
DynamicValidator
control
catches unhandled validation exceptions thrown by the
EntityDataSource
associated with
the
FormView
. Chapter 8, “Implementing Entity Validation,” provides detailed discussion
of this topic.
Listing 6.4 shows the code-behind file of the Edit page template.
LISTING 6.4
Edit Page Template (Code-Behind)
using System;
using System.Web.DynamicData;
using System.Web.UI.WebControls;
namespace WebApplication.DynamicData.PageTemplates
{
public partial class Edit : System.Web.UI.Page
{
protected MetaTable table;
protected void Page_Init(object sender, EventArgs e)
{
this.table = DynamicDataRouteHandler.GetRequestMetaTable(Context);
this.Title = table.DisplayName;
this.dataSource.EntityTypeFilter = this.table.EntityType.Name;
this.dataSource.Include = this.table.ForeignKeyColumnsNames;
}
protected void FormView_ItemCommand(object sender, FormViewCommandEventArgs e)
{
if (e.CommandName == DataControlCommands.CancelCommandName)
this.Response.Redirect(this.table.ListActionPath);
}
protected void FormView_ItemUpdated(object sender, FormViewUpdatedEventArgs e)
{
if (e.Exception == null || e.ExceptionHandled)
this.Response.Redirect(this.table.ListActionPath);
}
}
}
Initialization code in the
Page_Init
event handler is identical to that in the Details page
template. The
FormView_ItemUpdated
event handler redirects the user to the List page after