I just posted a few new tutorials on ASP.NET MVC.
Category: Ajax
On Using the New Ajax Control Toolkit Html Editor

This announcement by Bertrand Le Roy on some new Ajax Control Toolkit controls was a nice bit of news to me the other day. One thing I was looking for was a new Html editor...great timing! Tonight I set out to implement it in one of my MVC projects.
Read More on "On Using the New Ajax Control Toolkit Html Editor" >>
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".
Read More on "Date.parseLocale Bug In ASP.NET Ajax Control Toolkit" >>
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.
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.
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.
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.
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.
But it didn't work perfectly. If you want to do the same, be prepared to deal with some issues.
- 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.
- 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.
- 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.
- Ref and out were often switched.
Now I have the MS ASP.NET Ajax library in code files.
So the plugin works pretty well, though things could be improved.
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.
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.
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!
I've been meaning to mention that I've been spending time using
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
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.

