Date.parseLocale Bug In ASP.NET Ajax Control Toolkit

So I ran into a weird one tonight. I have an ASP.NET page with a grid view and some text boxes. Two of the text boxes have CalendarExtenders on them. On initial load everything is peachy. But I select something in the Grid and fill in the values of the two text boxes on the server side...things go awry. I'm getting a javascript error, "Date.parseLocale is not a function".

There is a lengthy discussion of this in a post on the ASP.NET forums. Apparently this is a known issue. The last poster said it was fixed in a later version, but I'm using the latest and it definitely isn't.

However, one of the forum users posted a hack to get this working. And indeed it does. You just have to put this in the Page_Load function of the page that has the controls:


//Hack I found here: http://forums.asp.net/t/1068191.aspx<
if(ScriptManager.GetCurrent(this.Page) != null)
{
    if (!Page.ClientScript.IsStartupScriptRegistered("AjaxToolkitTempFix"))
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), "AjaxToolkitTempFix", "Date.parseLocale = function(s, f){return Date(s);};" + Environment.NewLine + "Sys.Debug = new Object();Sys.Debug.isDebug =  function(){return true};", true);
    }
}

Hope it works for you as well. Enjoy. I would put a note about how this doesn't work in the newest version and the hack is still necessary, but I kept getting a 404 when trying to login to the forums :)

Comments

Rush (8/31/2007 0:31 AM)

Thanks for posting about this. I wouldn't have gone through the trouble of looking through the forums but a quick google search is painless, and it worked! :-) I haven't tried the latest version though, maybe I should.

Eric (9/1/2007 9:53 AM)

I haven't tried to see if it's been fixed recently. If you find that it is, drop a note. I'd appreciate it.

Randy (8/24/2008 5:04 PM)

Saw that this posting was old, but thought I would tag this on the end of it so that anyone else that ran accross this problem could resolve it.  We use the calendar control in an application that is in production use.  No issues.  My dev machine was rebuilt.  Found the issue being described above.  Followed the instructions on a posting I found (url:  http://forums.asp.net/t/1068191.aspx?PageIndex=2) and have copied the content and pasted below.  It worked.  Seems there are two different versions of the ajax control toolkit.  Whatever you do, do not do the work around above before you try this below.  It worked for me.

Fix:  

I was also receiving this error on my production machine, however it worked fine on my development machine. Here's how I fixed mine (perform ALL these steps on BOTH development and production machines):

  1. Go to Add/Remove Programs and Uninstall ASP.NET AJAX Extensions 1.0 
  2. Re-install ASP.NET AJAX Extensions
  3. Download the latest AjaxControlToolkit (1.0.10618.0 at the time of this post)
  4. Make sure your website is using the latest AjaxControlToolkit.dll
  5. Start > Run > cmd.exe > iisreset /restart

You can tell if you have the wrong version of the ASP.NET AJAX Extensions by going to this folder:

C:\program files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\v1.0.61025\MicrosoftAjaxLibrary\System.Web.Extensions\1.0.61025.0

If you see "Debug" and "Release" folders - you have the old version. If you see a "Globalization" folder and a bunch of javascript files you have the newer version. Somehow it's all still "1.0".

Good luck!