Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Date validator when formatted

Reply
Thread Tools

Date validator when formatted

 
 
David C
Guest
Posts: n/a
 
      07-10-2009
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>


 
Reply With Quote
 
 
 
 
Stan
Guest
Posts: n/a
 
      07-10-2009
On 10 July, 22:41, "David C" <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
get date and time formatted Larry C++ 1 01-20-2010 02:10 AM
formatted date in grid view? Smokey Grindle ASP .Net 2 06-23-2006 11:09 AM
How To: Datagrid Date Column formatted if Null then "Active"? JDP@Work ASP .Net Web Controls 1 10-15-2004 07:38 PM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
How can i get the date formatted according to the regional settings made at the operating system level Karunakararao ASP .Net 0 05-11-2004 09:51 AM



Advertisments