Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compare Validator Control Error

Status
Not open for further replies.

lsmyth1717

Programmer
Mar 25, 2005
44
GB
Can someone help me. I'm trying to use the following validator control and compare a date to a date defined in the code-behind page. My code is below along with my error message I get when the page is rendering in the browser. Has anyone any idea what I've done wrong?

<asp:CompareValidator ID=cvDate Font-Size=small ForeColor=red Runat=server ErrorMessage="Please work"
Operator=LessThanEqual Type=Date ControlToValidate=txtStartDate ValueToCompare="<%#CompareDate()%>">*</asp:CompareValidator>

/// <summary>
/// Return a date for comparison
/// </summary>
/// <returns>a date string</returns>
public string CompareDate()
{
return DateTime.Today.ToShortDateString();
}

Browser Error Message
The value '' of the ValueToCompare property of 'cvDate' cannot be converted to type 'Date'.
 
The value '' of the ValueToCompare property of 'cvDate' cannot be converted to type 'Date'.
That means that it can't convert '' to a date as it isn't a valid date (i.e. it is null).

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Ok, but i've used this before and got this working fine so still can't understand it. My function that returns the date seems fine to me and should return a valid date and has done in the past. Any ideas what i've done wrong?
 
Well the error suggests that it isn't returning a valid date so you will have to check that it is

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top