ASP.net 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.

Categories

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPT

Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are as essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.

Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.