Databases Reference
In-Depth Information
Creating a New Page Template
Dynamic Data does not limit the set of page actions and page templates. You can easily
define a new action and create a new page template to handle it. As an example, consider
the action of deleting an entity instance. The default page templates support deletion
directly in the List and Details pages. When you click the Delete link on one of these
pages, a JavaScript prompt window is displayed, asking you to confirm the deletion.
Although this approach works, it definitely has a Windows-like feel to it. A more tradi-
tional way to do this in a web application is to take the user to a separate page where she
can review the entity she is about to delete and confirm the action.
Listing 6.9 shows the page template that implements the Delete page action. It is almost
identical to the built-in Details page template. Just like the other page templates, this
ASPX file needs to be placed in the DynamicData\PageTemplates folder of the web applica-
tion project, in a file called Delete.aspx.
LISTING 6.9 Delete Page Template (Markup)
<%@ Page Language=”C#” MasterPageFile=”~/Site.master” CodeBehind=”Delete.aspx.cs”
Inherits=”WebApplication.DynamicData.PageTemplates.Delete” %>
<asp:Content ContentPlaceHolderID=”main” runat=”server”>
<asp:DynamicDataManager runat=”server”>
<DataControls>
<asp:DataControlReference ControlID=”formView” />
</DataControls>
</asp:DynamicDataManager>
<h2>Are you sure you want to delete this from 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 ID=”formView” runat=”server” DataSourceID=”dataSource”
OnItemDeleted=”FormView_ItemDeleted”>
<ItemTemplate>
<asp:DynamicEntity runat=”server” />
<div class=”DDFormActions”>
<asp:Button runat=”server” CommandName=”Delete” Text=”Delete”/>
<asp:DynamicHyperLink runat=”server” Action=”List” Text=”Back to list”/>
</div>
</ItemTemplate>
</asp:FormView>
 
 
Search WWH ::




Custom Search