Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Date validator when formatted (http://www.velocityreviews.com/forums/t690821-date-validator-when-formatted.html)

David C 07-10-2009 09:41 PM

Date validator when formatted
 
I am trying to use a CompareValidator to validate an entered date in my
asp.net page. The date is being formatted on display and apparently the
CompareValidator does not like that. Is there a way around this? below is
the section of GridView where the problem exists. Thanks.
David

<asp:TemplateField HeaderText="Activity Date"
SortExpression="ActivityDate" ItemStyle-Width="120">
<EditItemTemplate>
<asp:TextBox ID="txtActivityDate" runat="server"
Text='<%# Bind("ActivityDate", "{0:M/d/yyyy h:m tt}") %>'></asp:TextBox>
<asp:CompareValidator ID="valActivityDate"
runat="server" ErrorMessage="Activity Date must be a valid date"
Operator="DataTypeCheck" Type="Date"
Display="Dynamic"
ControlToValidate="txtActivityDate"></asp:CompareValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("ActivityDate", "{0:M/d/yyyy h:m tt}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>



Stan 07-10-2009 11:11 PM

Re: Date validator when formatted
 
On 10 July, 22:41, "David C" <dlch...@lifetimeinc.com> wrote:
> I am trying to use a CompareValidator to validate an entered date in my
> asp.net page. The date is being formatted on display and apparently the
> CompareValidator does not like that. *Is there a way around this? *below is
> the section of GridView where the problem exists. Thanks.
> David
>
> * * * * * * * * <asp:TemplateField HeaderText="Activity Date"
> SortExpression="ActivityDate" ItemStyle-Width="120">
> * * * * * * * * * * <EditItemTemplate>
> * * * * * * * * * * * * <asp:TextBox ID="txtActivityDate" runat="server"
> Text='<%# Bind("ActivityDate", "{0:M/d/yyyy h:m tt}") %>'></asp:TextBox>
> * * * * * * * * * * * * <asp:CompareValidator ID="valActivityDate"
> runat="server" ErrorMessage="Activity Date must be a valid date"
> * * * * * * * * * * * * * * * * Operator="DataTypeCheck" Type="Date"
> Display="Dynamic"
> ControlToValidate="txtActivityDate"></asp:CompareValidator>
> * * * * * * * * * * </EditItemTemplate>
> * * * * * * * * * * <ItemTemplate>
> * * * * * * * * * * * * <asp:Label ID="Label1" runat="server" Text='<%#
> Bind("ActivityDate", "{0:M/d/yyyy h:m tt}") %>'></asp:Label>
> * * * * * * * * * * </ItemTemplate>
> * * * * * * * * </asp:TemplateField>


Hi

You may be using the wrong type of validator. The CompareValidator
works by comparing the input with another control value or a constant.
You dont specify either in your code.

Perhaps a RegularExpressionValidator would be more appropriate.


All times are GMT. The time now is 09:54 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.