Date.parseLocale Bug In ASP.NET Ajax Control Toolkit

14 June 2007

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:

   1:  //Hack I found here: http://forums.asp.net/t/1068191.aspx
   2:  if (ScriptManager.GetCurrent(this.Page) != null)
   3:  {
   4:      if (!Page.ClientScript.IsStartupScriptRegistered("AjaxToolkitTempFix"))
   5:      {
   6:          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);
   7:      }
   8:  }
   9:  

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:3

New Resources

22 May 2007

Along with the redesign comes a few new resources.

First, there is now an articles section. That's where I'll be putting article-type stuff.

Second, there are a couple new or improved resources there. My silverlight/inline xaml/firefox article has been updated for beta 1. There is also a little thing on the ASP.NET Ajax fade animation and editing Visual Studio 2005 templates.

Third, added a few reviews to the book reviews page. I think I had them referenced in my blog, but I forgot to put links to them on that page. 

Comments:0

Local Cardspace and ASP.NET Ajax Training

05 April 2007

Microsoft has some free training in Dallas May 3. See here for information. I'm signed up. Let me know if you're going so we can chat.

Comments:0

ASP.NET Ajax Released

23 January 2007

I've never played with CTP's, betas and RC's of any chunk of software as much as I've played with ASP.NET Ajax. That's probably why I'm so very happy that it is finally released. Yay!!! If you are a .NET web developer and haven't tried it, I highly recommend doing so.

Comments:0

Using ASP.NET Ajax in a Non ASP.NET Site

11 January 2007
So I saw a question on the forums about how to use the ASP.NET Ajax libraries outside of an ASP.NET application. I decided to write one. As it turns out, it is really simple to use at least part of them.

Steps:
1. Install all the ASP.NET Ajax libraries. At the very least you will need the main Ajax install. If you want to use the js in the preview library (CTP), you should install it as well. These files should show up somewhere around here: C:\Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\v1.0.61025\MicrosoftAjaxLibrary\System.Web.Extensions\1.0.61025.0\Release
2. Create an html page.
3. Make a reference to the scripts.
4. Write whatever html you want to write that you would use the javascript code.
5. Write the javascript code.

You're done. Here is an example using the preview library code that I've posted about before. All you need to run this is this html and the javascript libraries previously mentioned. The first two lines in the function "hideThatDiv" use MicrosoftAjax.js. The rest use PreviewScript.js and PreviewGlitz.js. Note the complete lack of any ASP.NET code in this...

   1:  <html>
   2:      <head>
   3:          <script language="javascript" src="MicrosoftAjax.js"></script>
   4:          <script language="javascript" src="PreviewScript.js"></script>
   5:          <script language="javascript" src="PreviewGlitz.js"></script>
   6:          <script language="javascript">
   7:              function hideThatDiv()
   8:              {
   9:                  var element = $get('targetDiv');
  10:                  var target = new Sys.UI.Control(element);
  11:                  
  12:                  var fadeAnimation = new Sys.Preview.UI.Effects.FadeAnimation();
  13:                  fadeAnimation.set_target(target);
  14:                  fadeAnimation.set_duration(1);
  15:                  fadeAnimation.set_fps(25);
  16:                  fadeAnimation.set_effect(Sys.Preview.UI.Effects.FadeEffect.FadeOut);
  17:                  fadeAnimation.play();
  18:              }
  19:          </script>
  20:      </head>
  21:      <body>
  22:          <div id="targetDiv" style="background-color: Black; width: 200px; height: 200px;">
  23:          </div>
  24:          <input type="button" onclick="hideThatDiv();" value="Hide the div" />
  25:      </body>
  26:  </html>

 There is a lot more there than this, but this is a basic example of how to use some of the scripts.
Comments:0

ASP.NET Ajax Preview Script Loading Error

08 January 2007

Here is a little tip of you're playing around with the "Futures December CTP". If you have been using earlier version of the preview code, you might end up putting this in your ScriptManager to load the preview scripts:

   1:  <asp:ScriptReference
   2:       Assembly="Microsoft.Web.Preview" 
   3:       Name="PreviewScript.js" />
   4:  <asp:ScriptReference 
   5:       Assembly="Microsoft.Web.Preview"
   6:       Name="Microsoft.Web.Resources.ScriptLibrary.PreviewGlitz.js" />

Bad idea. If you'll do this you'll get either of the following error messages:

1. Assembly 'Microsoft.Web.Preview, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not contain a Web resource with name 'Microsoft.Web.Resources.ScriptLibrary.PreviewGlitz.js'
2. Assembly 'Microsoft.Web.Preview, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not contain a Web resource with name 'Microsoft.Web.Resources.ScriptLibrary.PreviewScript.js'

To fix this, just remove the "Microsoft.Web.Resources.ScriptLibrary." from the "Name" attribute. Was having this problem. Noticed the fix here.
Comments:2

Hooking Up Slider Extender to Client-Side Code

20 December 2006

Now that the RC for ASP.NET Ajax is out, we're just around the bend from release. Thank goodness.

So I downloaded the RC and the control toolkit and started playing with the slider, since I would like to use it for a project. Unfortunately, it took me a while to figure out how to hook up clients-side javascript events to the slider. A forum post finally solved my problem. I figured I would share the solution.

            
Sys.Application.add_load(application_Load);

function application_Load()
{
var behavior = $find('funkyBehaviorId');

//$find('funkyBehaviorId').add_valueChanged(function() { onDoSomething(); });
//$find('funkyBehaviorId').add_valueChanged(onDoSomething);
//$find('funkyBehaviorId').get_events().addHandler("valueChanged", onDoSomething);

//behavior.add_valueChanged(function() { onDoSomething(); });
//behavior.add_valueChanged(onDoSomething);
behavior.get_events().addHandler("valueChanged", onDoSomething);
}

function onDoSomething(sender, e)
{
var div = $get('showMeSomething');
var textbox = $get('_sliderTarget');

div.innerHTML = "" + textbox.value + "";
}

<asp:Panel runat="server" ID="hi">
<asp:TextBox ID="_slider" runat="server" />
<toolkit:SliderExtender runat="server" TargetControlID="_slider" BehaviorID="funkyBehaviorId" ID="_sliderExtender" BoundControlID="_sliderTarget">
</toolkit:SliderExtender>
</asp:Panel>

<asp:TextBox runat="server" ID="_sliderTarget" />

<div id="showMeSomething"></div>


All of the lines in the application load method work. They are all just variations on the same theme. Use whatever style you like. Use the $find method to find the sliderextender based on its behavior id, and attach to some events. The key that I didn't figure out for quite a while was to hook up to the slider extender via behavior id, not to its id or the id of the target. Once I found that out, everything went pretty smoothly.

Comments:0

ASP.NET Ajax RC is Here!

15 December 2006
Yay! I can't wait to get started with it. You can download it from the MS website for ASP.NET Ajax. They are, as of this posting apparently, updating the website. Five minutes ago the images still said Beta 2. Now they say RC :)
Comments:0

Decompiling the ASP.NET Ajax Library

07 December 2006
So in an attempt to look deep into the bowels of the UpdatePanel of ASP.NET Ajax, I decided to employ one of my favorite geek tools, Reflector. Reflector has a nice interface, but Visual Studio's is a little better, so I tried out one of the addins that actually dumps the decompiled dll into text files. I ended up using this one. It actually creates the class library and pulled the javascript files out of the Microsoft.Web.Extensions library. Pretty cool.

But it didn't work perfectly. If you want to do the same, be prepared to deal with some issues.

  1. Private classes aren't handled well. This is actually a problem with Reflector, not with the plugin. Only two classes (that I could find) used them, so those had to be manually fixed.
  2. Enums were decompiled as their integer values. C# will not implicitly cast an int to an enum, so all of those ints had to be cast.
  3. Properties where not properly decompiled, but that's not a surprise. As you .NET geeks surely know, properties are syntactic sugar, and are compiled in IL to get_ and set_ methods. These showed up in the decompiled C# code, and had to be changed to properties manually.
  4. Ref and out were often switched.
After fixing a little over four hundred syntax errors, everything was fine :). It actually went pretty quickly, since most things fell into the above four categories, and those are easy to fix.

Now I have the MS ASP.NET Ajax library in code files.

So the plugin works pretty well, though things could be improved.


Comments:0

Sys.Preview.UI.Effects.Glitz.interpolate Method

17 November 2006
When you poke around the ASP.NET Ajax javascript files you can find some pretty interesting stuff. This one might come in handy. It's used in a number of the animations. It and the animations can be found in PreviewGlitz.js.

Let's say you have two points, 100 and 30, and want to know the point that is 85% of the way from 100 to 30. Call the interpolate method.

Sys.Preview.UI.Effects.Glitz.interpolate(100, 30, 85);

The first value is the start point, the second the end point, and the latter the percentage. The result in this case is 40.5. At 90% it is 37. At 95% it is 33.5. You get the point.

So if you need it...now you know it's there.
Comments:0

ASP.NET Ajax Fade Animation and NDDNUG

17 November 2006
This is a test post. So my blog is being syndicated through the NDDNUG site. Normally my posts show up. For some reason, one I did on ASP.NET Ajax fade animations did not (the original post is here). This is sorta ironic, since that's the only post I've done since the syndication began that actually included code. Will this post show up? We'll have to see...
Comments:2

Using the ASP.NET Ajax Fade Animation

15 November 2006
So I think I mentioned before that I've been playing around with the new Ajax bits from Microsoft. Currently we're up to beta 2. Get it here.

Want to know how to use the fade animation? It's pretty easy. Here's the javascript:

//Instantiate a control with the div to animate
//'faderDiv' is the id of the control to fade
var target = new Sys.UI.Control($get('faderDiv'));

var fadeAnimation = new Sys.Preview.UI.Effects.FadeAnimation();
//The control-wrapped element to fade fadeAnimation.set_target(target); //The duration that the animation will last, in seconds fadeAnimation.set_duration(1); //The frames-per-second for the animation fadeAnimation.set_fps(25); //Fade in or fade out? Set it here fadeAnimation.set_effect(Sys.Preview.UI.Effects.FadeEffect.FadeOut); //Execute the animation fadeAnimation.play();


The javascript actually pretty straightforward, as you can see.

This functionality is not in beta 2, but the somewhat confusing value-add ctp. You'll need to download that as well as the beta to do this.

You reference the javascript resources in the ScriptManager on the page. Like this:

<asp:ScriptManager ID="ScriptManager1" runat="server">
  <Scripts>
    <asp:ScriptReference
      Assembly="Microsoft.Web.Preview"
      Name="Microsoft.Web.Resources.ScriptLibrary.PreviewScript.js" />
    <asp:ScriptReference
      Assembly="Microsoft.Web.Preview"
      Name="Microsoft.Web.Resources.ScriptLibrary.PreviewGlitz.js" />
  </Scripts>
</asp:ScriptManager>


Other stuff to keep in mind. First, don't forget to modify your web.config. You'll definitely need the following in your handlers section (If you get 'Sys is not defined', this is probably why).
<add verb="GET"
     path="ScriptResource.axd"
     type="Microsoft.Web.Handlers.ScriptResourceHandler"
     validate="false"/>

Of course, check the documentation and samples on the ajax.asp.net site for more info.
Comments:13

ASP.NET Ajax Beta Release

24 October 2006
So I've been playing around with the latest CTP for MS's Ajax framework (http://ajax.asp.net/). Good news, a beta finally came out. Rock on...

Bad news, it has changed incredibly :). Actually, it's not bad that it changed. It seems to have changed for the good. I just have to unlearn some stuff...that's what I get for messing around with CTP's!
Comments:0

Atlas Is Not So Bad...

18 October 2006
Actually, it is quite good.

I've been meaning to mention that I've been spending time using Atlas Microsoft Ajax lately. Here my initial thoughts:

1. I have never picked up a new set up libraries that did no such with so little work. Some of this stuff is, frankly, freakishly easy to use. I am just floored by the simplicity and functionality of the UpdatePanel control.

2. The above being said, it is an interesting experience coding seriously with a CTP. I played around with .NET 2.0 when it was CTP, and with Indigo Windows Communication Foundation when it was CTP, but never to the extent that I have this. And you do get some of the issues you would expect to come with using a CTP. There are some bugs. Documentation is spotty at times. But, in general, it is solid. I would have no qualms using it in production assuming there is plenty of QA (but isn't that true of everything?).

3. I'm REALLY glad it is built on 2.0, and doesn't need to wait for 3.0 to be released. Of course then I found out that 3.0 is basically all written on the 2.0 runtime, so that's not going to require a new framework. Sweet...

4. They are supposedly going to release it by the end of the year. I really hope they succeed. There is a go-live license out now so it can be used in production with no problem, but it will be nice when it has been stabalized. One of the problems currently is that the changes haven't hit all of the online (and obviously print) materials. Once it gets released, good stable documentation can be released. That will be nice.
Comments:0