You almost have it right. You used the old <%= %> ASP style tags. They don't
work inside of properties. DataBinding tags do: <%# [code] %>.
<asp:rangevalid ator id="startDateVa lidator" runat="server" Type="Date"
MinimumValue="1/1/2000" MaximumValue=<% # DateTime.Now.To ShortDateString ()%>
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:
startDateValida tor.DataBind();
Here's assigning directly:
startDateValida tor.MaximumValu e = DateTime.Now.To ShortDateString ()
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 Comparevalidato r with Operator=DataTy peCheck and Type=Date.
--- Peter Blum
www.PeterBlum.c om
Email: PL****@PeterBlu m.com
Creator of "Profession al Validation And More" at
http://www.peterblum.c om/vam/home.aspx
"VC" <vu***@mailbloc ks.com> wrote in message
news:e2******** ******@TK2MSFTN GP14.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:rangevalid ator id="startDateVa lidator" runat="server" Type="Date"
MinimumValue="1/1/2000"
MaximumValue=<% =DateTime.Now.T oShortDateStrin g()%>
.
.
.
</asp:rangevalida tor >
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?