Detailview in Gridview, unable to use the PropertyProxyValidator for validation

Topics: General discussion, Validation Application Block
Jul 19, 2007 at 4:31 AM
hi all, here is my current situation,

i am using WCSF and Enterprise library 3.1. i got a entity class (PEMS.CallReason.Entities.CallReasonInfo) which i make the properties wrapped by the validation application block.
ie (VB)
:
<NotNullValidator(messageTemplate:="Cannot be empty", Ruleset:="Primary")> _
<StringLengthValidator(3, RangeBoundaryType.Inclusive, 10, RangeBoundaryType.Inclusive, messageTemplate:="Min 3, Max 10", Ruleset:="Primary")> _
Public Property ReaCode() As String
Get
Return reacode
End Get

Set(ByVal value As String)
reacode = value
End Set
End Property

and i got an gridview for displaying data. i make use of the <EmptyDataTemplate> of gridview and put a detailview inside. the detailview is used for inserting data.
i bind a propertyproxyvalidator to the textbox control

<cc1:PropertyProxyValidator ID="ReaCodeValidator" runat="server" PropertyName="ReaCode" RulesetName="Primary"
SourceTypeName="PEMS.CallReason.Entities.CallReasonInfo" ValidationGroup="InsertValidationControls" ControlToValidate="txtAddReaCode" ErrorMessage="error" SetFocusOnError="true" >#</cc1:PropertyProxyValidator>--%>


the propertyproxyvalidation can work, however, i cant display the error message and it just clears my textboxes.

i can get the validation to work by traditional validators
IE:

<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtAddReaCode"
ErrorMessage="You must provide the reacode" validationGroup="InsertValidationControls"> * </asp:RequiredFieldValidator>
<asp:CompareValidator ID="CompareValidator2" runat="server" ControlToValidate="txtAddReaCode"
ErrorMessage="The reacode must be greater than or equal to zero and cannot include the currency symbol"
Operator="GreaterThanEqual" Type="String" ValueToCompare="3" ValidationGroup="InsertValidationControls">* cannot less than 3 </asp:CompareValidator>

may i know is it not support by propertyproxyvalidor to work on detailview or just my wrong syntax/handling?
i really wan to use propertyproxyvalidator, i can get it work on normal forms. but it seems cant be run inside a detailview...

please help

thanks,
Martin
Jul 22, 2007 at 1:26 PM
I am also facing similar problem.

The propertyproxyvalidator seem won't work under the GridView.

And it seems work fine with "normal" validator.

Thanks.
Jul 23, 2007 at 5:41 PM
Hi,

Can you provide a more detailed description of the problem as well as a small repro. Just "won't work" is unfortunately not enough to understand the problem.

The snippets below show how to use the property proxy validator with both GridView and DetailsView (although not combined as in the original post). Can you describe what is different between your code and the snippets to understand the root issue?

Regards,
Fernando

C# code

public class Customer
{
public Customer(string name)
{
this.name = name;
}

private string name;

[NotNullValidator]
[StringLengthValidator(10)]
public string Name
{
get { return name; }
set { name = value; }
}
}


DetailsView

<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False"
DataSourceID="ObjectDataSource1" Height="50px" Width="125px">
<Fields>
<asp:CommandField ShowEditButton="True" />
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<%#Eval("Name")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="Name" runat="server" Text='<%#Bind("Name")%>'></asp:TextBox>
<entlibvalidation:PropertyProxyValidator ID="Name_Validator" runat="server" SourceTypeName="Customer"
PropertyName="Name" ControlToValidate="Name" />
</EditItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>

GridView

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="ObjectDataSource1">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:TemplateField>
<ItemTemplate>
<%#Eval("Name")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="Name" runat="server" Text='<%#Bind("Name")%>'></asp:TextBox>
<entlibvalidation:PropertyProxyValidator ID="Name_Validator" runat="server" SourceTypeName="Customer"
PropertyName="Name" ControlToValidate="Name" />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Aug 6, 2007 at 9:33 AM
mates i got the reason for my validators not working, cos i had my page loaded twice :P

thx anyway,
marty