User input date Validating

  • Thread starter Thread starter Tamer Ibrahim
  • Start date Start date
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 ?
 
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
 
Back
Top