Tuesday 15 April 2014

RangeValidator Control Date Checking Error


Server Error in '/' Application.


 

The value '15/04/2024' of the MaximumValue property of 'RangeValidator2' cannot be converted to type 'Date'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 


[HttpException (0x80004005): The value '15/04/2024' of the MaximumValue property of 'RangeValidator2' cannot be converted to type 'Date'.]
   System.Web.UI.WebControls.RangeValidator.ValidateValues() +1482938
   System.Web.UI.WebControls.RangeValidator.ControlPropertiesValid() +12
   System.Web.UI.WebControls.BaseValidator.OnPreRender(EventArgs e) +36
   System.Web.UI.Control.PreRenderRecursiveInternal() +83
   System.Web.UI.Control.PreRenderRecursiveInternal() +155
   System.Web.UI.Control.PreRenderRecursiveInternal() +155
   System.Web.UI.Control.PreRenderRecursiveInternal() +155
   System.Web.UI.Control.PreRenderRecursiveInternal() +155
   System.Web.UI.Control.PreRenderRecursiveInternal() +155
   System.Web.UI.Control.PreRenderRecursiveInternal() +155
   System.Web.UI.Control.PreRenderRecursiveInternal() +155
   System.Web.UI.Control.PreRenderRecursiveInternal() +155
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974
 
I have encountered this problem when try to use range validator control.
The reason is because the server date locale setting is "mm-dd-yyyy" (en-US) format. But I'm trying to assign "wrong" value "15/04/2004" (which in my application, i'm using dd/mm/yyyy format across all my date value) into the range validator maximum value.
To overcome this problem, these are what i do.