Validation & DetailsView Problem

Topics: Validation Application Block
Aug 24, 2007 at 11:51 AM
Hi,
I've got 1 problem and also i'm looking for some architectural advise.
Firstly, I cant seem to get the validation working on a detailsView with a objectdatasouce, i know previous posts have already mentioned/solved this but I've not
had any luck. The code is fairly simple. ServiceDatasource is a an objectDatasource that has been extended and provides a singleton to use for
the method calls. When the insert button is fired from within the DetailsView it doesnt use the validation.

Any ideas???
Regards,
Michael

<%@ Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="CustomersList.aspx.cs" Inherits="TechControl.TechControlSample.Web.Forms.CustomersList"
Theme="Default" Title="Customers" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<TC:ServiceDatasource ID="customersDatasource"
runat="server"
TypeName="ISampleService"
SelectMethod="CustomerGetAll">
</TC:ServiceDatasource>
<TC:ServiceDatasource ID="customerDatasource"
runat="server"
TypeName="ISampleService"
DataObjectTypeName="Customer"
SelectMethod="CustomerGet"
InsertMethod="CustomerSave"
OnInserting="customerDatasource_Inserting">
<SelectParameters>
<asp:ControlParameter ControlID="customersGrid" Name="customerId" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</TC:ServiceDatasource>

<fieldset style="width: 800px;">
<legend>
Customers
</legend>
<div style="height: 300px; width: 800px; overflow: auto; margin: 1em 1em 1em 1em;">
<asp:GridView ID="customersGrid"
runat="server"
AutoGenerateColumns="False"
AllowSorting="true"
DataSourceID="customersDatasource"
DataKeyNames="CustomerId"
SkinID="GridViewNormal"
EmptyDataText="No customers.">
<Columns>
<asp:TemplateField Visible="false">
<ItemTemplate>
<asp:HiddenField ID="versionTS" runat="server" Value='<%# Bind("VersionTS") %>'/>
<%--<asp:HiddenField ID="HiddenField1" runat="server" Text='<%# Bind("VersionTS", "{0:dd/MM/yyyy}") %>'/>--%>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Description" HeaderText="Description" />
</Columns>
</asp:GridView>
<asp:DetailsView ID="customerDetails"
runat="server"
DataSourceID="customerDatasource"
DataKeyNames="CustomerId, VersionTS"
AutoGenerateRows="False"
DefaultMode="Insert">
<HeaderTemplate>
<fieldset>
<legend>
Customer
</legend>
</HeaderTemplate>
<Fields>
<asp:TemplateField HeaderText="Description">
<InsertItemTemplate>
<asp:TextBox ID="descriptionText" runat="server" Text='<%# Bind("Description") %>'/>
<EntLib:PropertyProxyValidator ID="descriptionValidator"
runat="server"
SourceTypeName="TechControl.TechControlSample.Domain.Customer"
PropertyName="Description"
ControlToValidate="descriptionText"/>
</InsertItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowInsertButton="True" />
</Fields>
<FooterTemplate>
</fieldset>
</FooterTemplate>
</asp:DetailsView>
</div>
</fieldset>
<asp:Button ID="saveButton" runat="server" Text="Save Test" OnClick="saveButton_Click" />
</asp:Content>

ToolboxBitmap(typeof(ObjectDataSource))
public class ServiceDatasource : ObjectDataSource
{
public ServiceDatasource()
{
TypeName = "ISampleService";
ObjectCreating += ServiceDatasource_ObjectCreating;
ObjectDisposing += ServiceDatasource_ObjectDisposing;
Selecting += new ObjectDataSourceSelectingEventHandler(ServiceDatasource_Selecting);
}

private static void ServiceDatasource_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
{

}

/// <summary>
/// We will handle the lifecycle of the datasource manually
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private static void ServiceDatasource_ObjectDisposing(object sender, ObjectDataSourceDisposingEventArgs e)
{
e.Cancel = true;
}

/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private static void ServiceDatasource_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
{
e.ObjectInstance = Global.Service;
}
}