How to validate a TextBox for DateTime Check in ASP.net?

How to validate a TextBox for DateTime Check?
What is the equivalent for IsDate function in c#?


Date Added:
         <asp:TextBox
                  ID="DateAddedTextBox"
                  runat="server"
                 Text='<%#
Bind("DateAdded") %>'>
          </asp:TextBox>              



<asp:CustomValidator
            ID="CustomValidator1"
            runat="server"

            ControlToValidate="DateAddedTextBox"
            Display="Dynamic"
           ErrorMessage="Please
Enter Proper Date!" onservervalidate="CustomValidator1_ServerValidate"
SetFocusOnError="True"
           Text='<%# Eval("DateAdded") %>'
          ValidateEmptyText="True">
</asp:CustomValidator>

protected void CustomValidator1_ServerValidate(object
source, ServerValidateEventArgs args)
{
 try
     {  
          System.DateTime dt =
System.DateTime.Parse(args.Value);
         args.IsValid = true;
      }
catch
     {
         args.IsValid =
false;
      }

No comments: