User input date Validating

T

Tamer Ibrahim

Hi,

I'm trying to validate user input date using range validator on a text box .
This code is throwing this exception

"The value 'DateTime.Now;' of the MaximumValue property of 'rvQDate' cannot
be converted to type 'Date'. "

<asp:TextBox ID="txtQDate" runat="server" Enabled="False"></asp:TextBox>

<asp:Image ID="iQDate" runat="server" ImageUrl="~/images/Calendar.png"
Visible="False" />

<cc1:CalendarExtender ID="calQDate" runat="server" BehaviorID="calQDate"
TargetControlID="txtQDate" PopupButtonID="iQDate" Format="dd/MM/yyyy">

</cc1:CalendarExtender>

<asp:RangeValidator ID="rvQDate" runat="server" ControlToValidate="txtQDate"
Display="Dynamic"

ErrorMessage="Invalid QDate." MaximumValue="DateTime.Now;" Type="Date"
CultureInvariantValues="True">*</asp:RangeValidator>

How can I solve this ?
 
R

Riki

Tamer said:
Hi,

I'm trying to validate user input date using range validator on a
text box . This code is throwing this exception

"The value 'DateTime.Now;' of the MaximumValue property of 'rvQDate'
cannot be converted to type 'Date'. "

<asp:TextBox ID="txtQDate" runat="server"
Enabled="False"></asp:TextBox>
<asp:Image ID="iQDate" runat="server" ImageUrl="~/images/Calendar.png"
Visible="False" />

<cc1:CalendarExtender ID="calQDate" runat="server"
BehaviorID="calQDate" TargetControlID="txtQDate"
PopupButtonID="iQDate" Format="dd/MM/yyyy">
</cc1:CalendarExtender>

<asp:RangeValidator ID="rvQDate" runat="server"
ControlToValidate="txtQDate" Display="Dynamic"

ErrorMessage="Invalid QDate." MaximumValue="DateTime.Now;" Type="Date"
CultureInvariantValues="True">*</asp:RangeValidator>

How can I solve this ?

You can not set the MaximumValue="DateTime.Now" like that (declaratively).
This will cause the value to be set to the literal string value, which
throws an error.

You can set it programmatically, though.
Leave the MaximumValue empty, and add this line to the Page_Load event:
rvQDate.MaximumValue=DateTime.Now
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top