lsmyth1717
Programmer
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'.
<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'.