CompareValidator for date validation issue solved

Now before I start this is not a problem with the control, as it turned out it was a problem with the environment. I had set up a text field to take a date and then validate that date using a DataTypeCheck in a ASP.Net CompareValidator. On my localhost and on the testing site I had no problems, and it only fired when the date was invalid (as you would expect), but on the laptop I found it had fallen over and would not save because the date was invalid.

The first problem was to find out was it actually the validator client side or server side as I have backup code int he event the user turns off JavaScript that performs the same job server-side. After a quick firebug and check of the server logs I determined that it was limited to client-side validation, which raised the question, why? Surely the testing server and the laptops JavaScript should not have changed, after deeper examination I came across the line in the client-side JavaScript.

DateValidator_13.dateorder = "mdy";

It was the american date format, it should have been “dmy”, this again raised the question why? Obviously it was a system setting, and after altering the IIS region setting to English (United Kingdom) problem solved. Just goes to show it pays to make sure all the environment settings are correct when deploying code onto a new machine.

Update: This has happened a couple of times, so to make sure the code is correct whatever machine this is deployed on I added  Culture=”en-GB” to the <%@ Page attribute, so that it associates with the correct culture wherever it is loaded.