custom validator for last day of a month - c#

Nathantaylor

New Member
I'm new to asp.net, so plz bear with me: I want to create a custom validator to check if the input date given in a textbox (which has a calendar extension(AJAX)) is the last day of a month or not. Here is what I tried to do:\[code\]protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs e){ DateTime dt = Convert.ToDateTime(e.ToString("dd/MMM/yyyy")); DateTime lastOfMonth = new DateTime(dt.Year, dt.Month, 1).AddMonths(1).AddDays(-1); if (dt == lastOfMonth) { e.IsValid = true; } else { e.IsValid = false; }}\[/code\]I think the problem is the way I'm handling the object 'e'. Any help is greatly appeciated. Thanks a lot in advance!
 
Back
Top