tags:

views:

27

answers:

1

Hi,

I need to validate a textbox to ensure the submit date is older than Today. I wanted to use a CompareValidator to do that, but unfortunately the following code doesn't work:

<asp:CompareValidator ID="cvtbDateExpiration" ControlToValidate="tbDateExpiration"
    Operator="GreaterThan" Type="Date" ValueToCompare="<%= DateTime.Today %>"   
    ErrorMessage="Card has expired" runat="server" />

The compiler tells me that ValueToCompare="<%= DateTime.Today %>" is wrong: "This is not scriptlet. Will be output as plain text."

Is there a simple way to achieve this (without setting it using the Code Behind)?

Thanks!

+1  A: 

It's generally set as follows:

ValueToCompare='<%# DateTime.Today.ToString("MM/dd/yyyy") %>'

... and you have to call DataBind() on the control (directly or indirectly).

Nariman