You almost have it right. You used the old <%= %> ASP style tags. They don't
work inside of properties. DataBinding tags do: <%# [code] %>.
<asp:rangevalidator id="startDateValidator" runat="server" Type="Date"
MinimumValue="1/1/2000" MaximumValue=<%# DateTime.Now.ToShortDateString()%>
But with databinding, you are required to call the DataBind() method on the
control or the Page to apply it. That means you are going to use some code
in Page_Load. Since that's required, I recommend assigning the property
directly.
Here's databinding:
startDateValidator.DataBind();
Here's assigning directly:
startDateValidator.MaximumValue = DateTime.Now.ToShortDateString()
The second case is much faster.
Because so many users miss this issue when validating ranges, I wanted to
point it out to you. The RangeValidator will not report an error until the
text is a valid date format because it cannot compare an illegal date to the
range. You should always have a validator for the format of the field. In
this case, its Comparevalidator with Operator=DataTypeCheck and Type=Date.
--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
"VC" <vu***@mailblocks.com> wrote in message
news:e2**************@TK2MSFTNGP14.phx.gbl...
I have a textbox where users type in a date. I want to check that the input
is between year 2000 and the current date.
Here is segment of the codes that give me the "Server tags cannot contain
<%...%> construct"
<asp:rangevalidator id="startDateValidator" runat="server" Type="Date"
MinimumValue="1/1/2000"
MaximumValue=<%=DateTime.Now.ToShortDateString()%>
.
.
.
</asp:rangevalidator >
Could anyone help me with codes/way to check whether a date input is
within a range of value, preferably without using the code behind?