Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Custom Validator
Message
From
10/10/2005 12:25:50
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01057025
Message ID:
01057707
Views:
15
William,

I think possibly the problem is that you're not specifically sending a string to your IsDate method. Try using:
if (!IsDate(e.Value.ToString()))
I don't have much WebForm experience, so if this isn't the problem, I probably don't have too many other suggestions, but give that a try and see if it helps.

~~Bonnie



>Hi All,
>
>I have a web form with 3 textboxes to receive dates also I have a custom validator and a method (validate_date) to validate one of the dates.
>
>private void Validate_date( object sender, ServerValidateEventArgs e)
>{
>			lblMessage.Text = "";
>			e.IsValid = true;
>			
>			if ( !IsDate( e.Value) )
>			{
>				e.IsValid = false;
>				
>				cv_IssuedDate.ErrorMessage = "Invalid Date!";
>				lblMessage.Text = "Issued Date Invalid";
>			}
>		}
>
>		public bool IsDate(string sdate)
>		{
>			DateTime dt;
>			bool isDate = true;
>			try
>			{
>				dt = DateTime.Parse(sdate);
>			}
>			catch (Exception e)
>			{
>				isDate = false;
>				lblMessage.Text = e.Message;
>			}
>			return isDate;
>		}
>
>The problem is that is always returning Invalid date even when I type a correct date
>Ex 01/01/01 or 01/01/2000
>
>Any help would appreciated,
>
>thanks
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform