Databases Reference
In-Depth Information
<asp:DynamicEntity runat=”server” Mode=”Edit” />
<div class=”DDFormActions”>
<asp:LinkButton runat=”server” CommandName=”Update” Text=”Update” />
<asp:LinkButton runat=”server” CommandName=”Cancel” Text=”Cancel”
CausesValidation=”false” />
</div>
</EditItemTemplate>
</asp:FormView>
<asp:EntityDataSource ID=”dataSource” runat=”server” EnableUpdate=”true” />
<asp:QueryExtender TargetControlID=”dataSource” runat=”server”>
<asp:DynamicRouteExpression />
</asp:QueryExtender>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
The Edit page also includes an EntityDataSource and QueryExtender controls to imple-
ment data access logic as well as a FormView and DynamicEntity controls to render the
user interface. However, unlike the read-only Details page template, which allows deleting
the current entity, the Edit page template enables you to edit the current entity, but not
delete it. Consequently, it sets the Mode property of the FormView and DynamicEntity
controls to Edit and sets EnableUpdate property of the EntityDataSource control to true .
As you recall from the discussion of entity templates in Chapter 5, “Filter Templates,”
setting the Mode of the DynamicEntity control to Edit instructs this control to choose an
appropriate edit-mode entity template, which includes editable controls, like TextBox and
DropDownList instead of the read-only Literal and DynamicHyperLink controls generated
by the read-only entity templates.
Setting DefaultMode of the FormView control to Edit makes it instantiate the
EditItemTemplate , which contains the DynamicEntity control along with two LinkButton
controls. The FormView control has built-in support for the Update command, so when the
user clicks the Update link, the current property values of the entity displayed by the
FormView are automatically validated and submitted to the EntityDataSource control to
be saved in the database. The Cancel link is used to abandon editing the current entity
and go back to the List page.
The Edit page template includes the ValidationSummary and DynamicValidator controls.
Although these controls are also included in the Details page template, they haven't been
discussed because validation plays a much more prominent role in the process of editing
entities compared to deletion. As you recall from the discussion of field templates in
Chapters 4, the individual field values are validated by the field templates with the help of
the ASP.NET validation controls, including the new DynamicValidator control, which
enforces validation rules based on the Data Annotation attributes. If any validation errors
are encountered, the validators embedded in the field templates indicate invalid fields by
displaying an asterisk next to the corresponding data entry controls. However, the complete
error messages are displayed by the ValidationSummary control on the Edit page template.
 
Search WWH ::




Custom Search