Databases Reference
In-Depth Information
LISTING 6.7 Insert Page Template (Markup)
<%@ Page Language=”C#” MasterPageFile=”~/Site.master” CodeBehind=”Insert.aspx.cs”
Inherits=”WebApplication.DynamicData.PageTemplates.Insert” %>
<asp:Content ContentPlaceHolderID=”main” runat=”Server”>
<asp:DynamicDataManager runat=”server”>
<DataControls>
<asp:DataControlReference ControlID=”formView” />
</DataControls>
</asp:DynamicDataManager>
<h2>Add new entry to table <%= table.DisplayName %></h2>
<asp:UpdatePanel runat=”server”>
<ContentTemplate>
<asp:ValidationSummary runat=”server” HeaderText=”List of validation errors”/>
<asp:DynamicValidator runat=”server” ControlToValidate=”formView”
Display=”None” />
<asp:FormView runat=”server” ID=”formView” DataSourceID=”dataSource”
DefaultMode=”Insert” OnItemCommand=”FormView_ItemCommand”
OnItemInserted=”FormView_ItemInserted”>
<InsertItemTemplate>
<asp:DynamicEntity runat=”server” Mode=”Insert” />
<div class=”DDFormActions”>
<asp:LinkButton runat=”server” CommandName=”Insert” Text=”Insert” />
<asp:LinkButton runat=”server” CommandName=”Cancel” Text=”Cancel”
CausesValidation=”false” />
</div>
</InsertItemTemplate>
</asp:FormView>
<asp:EntityDataSource ID=”dataSource” runat=”server” EnableInsert=”true” />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
The most important difference between the code-behinds of the Insert (see Listing 6.8)
and Edit (see Listing 6.4) page templates is the additional initialization step the Insert page
templates performs for the FormView control. Just like the List page template, it extracts
the names and values of the entity properties from the request URL and associates them
with the FormView control by calling the SetMetaTable extension method. The field
templates generated by the DynamicEntity control use this information to provide default
field values in their data entry controls. The FieldValue and FieldValueEditString prop-
erties of the FieldTemplateUserControl class respect the default values associated with
 
Search WWH ::




Custom Search