Date validator when formatted

Discussion in 'ASP .Net' started by David C, Jul 10, 2009.

  1. David C

    David C Guest

    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>
    David C, Jul 10, 2009
    #1
    1. Advertising

  2. David C

    Stan Guest

    On 10 July, 22:41, "David C" <> 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.
    Stan, Jul 11, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Karunakararao
    Replies:
    0
    Views:
    629
    Karunakararao
    May 11, 2004
  2. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,193
    Michael Borgwardt
    May 30, 2004
  3. Smokey Grindle

    formatted date in grid view?

    Smokey Grindle, Jun 22, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    3,007
    Smokey Grindle
    Jun 23, 2006
  4. Larry
    Replies:
    1
    Views:
    258
  5. JDP@Work
    Replies:
    1
    Views:
    143
    Scott Mitchell [MVP]
    Oct 15, 2004
Loading...

Share This Page