Databases Reference
In-Depth Information
<asp:EntityDataSource ID=”dataSource” runat=”server” EnableDelete=”true” />
<asp:QueryExtender TargetControlID=”dataSource” runat=”server”>
<asp:DynamicRouteExpression />
</asp:QueryExtender>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
The only substantial difference between this new Delete template and the built-in Details
template is the set of button and link controls. The new Delete template uses a Button
control instead of a LinkButton to make confirmation of deletion visually different from
merely requesting it. It also does not have an Edit link the Details page template uses to
take users to the Edit page.
Although they might seem unnecessary, the ValidationSummary and DynamicValidator
controls still play an important role in the Delete page template. If the user tries to delete
a Customer who placed one or more orders, a database error will occur due to a foreign
key constraint violation. As discussed in Chapter 8, database errors can be presented to the
Dynamic Data as instances of the ValidationException class. The DynamicValidator
control at the top of the page automatically displays unhandled ValidationException
errors in the ValidationSummary instead of generating a yellow screen of death.
After implementing the new Delete page template, you also need to modify the existing
templates to redirect the user to a new dynamic page generated by the new template
instead of displaying the JavaScript prompt. In both List and Details page templates,
replace the following LinkButton :
<asp:LinkButton runat=”server” CommandName=”Delete” Text=”Delete”
OnClientClick='return confirm(“Are you sure you want to delete this
item?”);'/>
with the following DynamicHyperLink control:
<asp:DynamicHyperLink runat=”server” Action=”Delete” Text=”Delete” />
And because the Details page will no longer delete the records, you can remove the
EnableDelete property from its EntityDataSource control in page markup and remove
the ItemDeleted event handler from the FormView control in the code-behind.
Figure 6.7 shows an example of the dynamically generated Delete page for the Product
entity type. The entity itself (labels and field values) looks similar to the dynamically
generated Details page, which is a great example of how page templates allow you to
implement different actions and data access logic while reusing the common presentation
logic encapsulated by the entity templates.
 
Search WWH ::




Custom Search