Script#: Past, Present, Future...

A new build of Script# is now available, complete with full support for creating Microsoft ASP.NET AJAX components, controls and behaviors... this post includes a video demonstration of building a script watermark behavior, and gives me a chance to reflect on this project exactly a year since its initial release...

Exactly one year ago, I first announced my Script# project. Script# is a tool that brings (or attempts to reuse) the c# programming and tooling experience to create a more productive approach to script authoring, especially when you're writing script frameworks or libraries.

So it's a nice (ok I admit, sort of planned) coincidence that today, I am releasing another significant release with some key functionality added: support for ASP.NET AJAX. I am willing to bet that this will be of interest to a number of folks! Specifically, this means that there is a mode in the compiler that allows you to write script that only depends on MicrosoftAjax.js rather than on my custom Script# runtime/framework. While I certainly hoped that the ASP.NET AJAX framework itself would have been written in Script# (it can be... the compiler supports it, but it isn't, simply because the compiler wasn't ready early enough in the product cycle), it doesn't mean that you can't use this approach for your own client script libraries.

Head over to the Script# project page for full details about what changed this release, and to download the bits. I have put together a little video just under 10 minutes, that demonstrates how I might write a textbox Watermark behavior in ASP.NET AJAX using Script#.



(Double-click to view in full-screen mode)

I tried to tie in a number of benefits of Script# into this little demo. It is quite natural to think in terms of intellisense, compile-time error checking, and a hands-down better OOP syntax than any alternative script pattern that simulates OOP can provide, and these are certainly key to bringing a lot of productivity. However, the list of benefits really don't stop there. Various features of the IDE such as code snippets and refactoring and an msbuild-based project system can be leveraged as well. The familiar c#-style doc-comments can be used to produce actual documentation, or they be incorporated into the class browsing experience within .NET Reflector like I did in the video. In fact, the very possibility of browsing assemblies in a rich class browser aids the process of discoverability...

Here is the c# code itself for the watermark behavior from the demo...

using System;
using System.DHTML;
using Sys;
using Sys.UI;

namespace MyControls {

    /// <summary>
    /// A behavior to add watermarking to a textbox.
    /// </summary>
    public class Watermark : Behavior {

        private string _watermarkText;
        private string _watermarkCssClass;
        private DomEventHandler _focusHandler;
        private DomEventHandler _blurHandler;

        public Watermark(TextElement e) : base(e) {
        }

        public string WatermarkText {
            get {
                return _watermarkText;
            }
            set {
                _watermarkText = value;
            }
        }

        public string WatermarkCssClass {
            get {
                return _watermarkCssClass;
            }
            set {
                _watermarkCssClass = value;
            }
        }

        public override void Dispose() {
            DomEvent.RemoveHandler(Element, "focus", _focusHandler);
            DomEvent.RemoveHandler(Element, "blur", _blurHandler);
            base.Dispose();
        }

        public override void Initialize() {
            base.Initialize();

            ShowWatermark();

            _focusHandler = OnFocus;
            _blurHandler = OnBlur;

            DomEvent.AddHandler(Element, "focus", _focusHandler);
            DomEvent.AddHandler(Element, "blur", _blurHandler);
        }

        private void HideWatermark() {
            TextElement textElement = (TextElement)Element;
            if (textElement.Value == _watermarkText) {
                textElement.Value = "";
                DomElement.RemoveCssClass(textElement, _watermarkCssClass);
            }
        }

        private void OnFocus(DomEvent e) {
            HideWatermark();
        }

        private void OnBlur(DomEvent e) {
            ShowWatermark();
        }

        private void ShowWatermark() {
            TextElement textElement = (TextElement)Element;
            if (textElement.Value == "") {
                textElement.Value = _watermarkText;
                DomElement.AddCssClass(textElement, _watermarkCssClass);
            }
        }
    }
}

Looking back over the past year, it has been great to see the positive feedback and interest, whether it came in the form of comments, emails or bug reports. I thought I'd share a few key interesting highlights. Originally Script# started as a means to writing functionality for AJAX applications against the DHTML DOM, and was fairly experimental in terms of whether it would scale at all. Over the year, it has grown to support Silverlight (yes, beta 1 is now supported), and the Virtual Earth map control. Furthermore, it supports out-of-the-browser scripting scenarios by supporting the Sidebar gadgets API, the IE7 RSS Feeds API, and the File System Object API as well. The full Script# framework itself has been written using Script#. Various groups within Microsoft (such as Messenger, Windows Live and Office) are now looking to Script# as a key aspect of their script development process, which has been a great source of validation, and continous improvement. I wrote a Thinkweek paper on Script# last winter, and it was quite well-received by BillG and his technical staff. However, perhaps the most personal metric that I've been able to relate to is that I've been able to switch over to using Script# when it comes to any form of serious scripting beyond basic prototyping/experimenting - for example my UpdateControls suite, and for my PhotoViewer and PhotoMap prototypes.

Going forward, the plan is to continue to incrementally improve the project based on feedback I receive. There are a few significant feature plans I have in particular around support for generics, and static linking on the compiler end, and things like RichTextBox, drag and drop, and a few Silverlight-related scenarios on the frameworks end of things. A longer list of items in the roadmap, along with lots more conceptual material, is listed in the Script# readme.

Posted on Monday, 5/21/2007 @ 6:24 PM | #Script#


Comments

37 comments have been posted.

Martin Laporte

Posted on 5/22/2007 @ 4:21 AM
I'm really glad to learn that Script# is being used inside Microsoft too. The more I use it, the more I was getting worried about it disappearing at some time and me being forced to go back editing those .js files directly *shivers*.

Denis

Posted on 5/22/2007 @ 4:52 AM
Great ! The gap between GWT and Script# is narrowing...

Kevin Dente

Posted on 5/22/2007 @ 7:20 AM
Fabulous! Now that it can target ASP.NET AJAX I can start looking at it more seriously.

Vikram

Posted on 5/22/2007 @ 9:21 AM
Wow, thanks for gettings this new version out. Just thinking from where do you get all that energy and time

Ganapathy

Posted on 5/22/2007 @ 12:09 PM
Hi Nikhil, Script# really made the gadget development simple. I was able to create a gadget for MS CRM in no time :). One thing that I found difficult was to attach event to links that were dynamically genrated.

Prashant

Posted on 5/22/2007 @ 12:11 PM
Is Script# going to be officially released by Microsoft some day? Or is it just a pet project?
I plan some long-term development in Script# so it is kind of important :) Could you please shed some more light on the future of Script#? Hows does it fit with the forthcoming DLR and Silverlight? I hope I am not asking for too much.

Dion

Posted on 5/22/2007 @ 5:36 PM
Hi Nikhil, I think Script# is really getting mature now! I used it to code against Silverlight 1.0 beta, and it really saved me a lot of time.
I ran into a small problem using the Script# runtime/framework on FireFox together with Silverlight (i.e. not able to call static methods in FireFox 1.5), but when I switched to the Microsoft Ajax framework it worked without any problems.
To be honest: I think it might be best to drop support for the your Script# engine, and only focus on the Microsoft Ajax library as engine (for which you basically only need MicrosoftAjax.js, and not the complete ASP.NET Ajax extensions).
Anyway, thanks for releasing this new version of Script#!

Eric Golpe

Posted on 5/23/2007 @ 2:50 AM
ooooooo new toys! I love new toys... and their fancy and productive... wooo hoo! Great job Nikhil!!

Andrew Yanovsky

Posted on 5/23/2007 @ 3:07 AM
Script# is a great invention even without Silverlight or ASP.NET AJAX support.

Dion

Posted on 5/23/2007 @ 4:05 AM
To avoid misunderstandings, what I meant was: I might be best to let Script# only depend on MicrosoftAjax.js in the futre, and drop support for the special Script# runtime engine. I think that's just easier for new development and support.
I really love Script#, and hope it gets an official release this year!!

Robertjan Tuit

Posted on 5/23/2007 @ 5:24 AM
Great work, i almost thought the project was abandoned but you have outdone yourself again!

Do you know of any official support microsoft will be giving Script# ?
Maybe to ship it with Visual Stduio Orca's?

Nikhil Kothari

Posted on 5/23/2007 @ 7:48 AM
Ganapathy: Not sure whats the difficulty with dynamically generated links - you essentially have the <a> elements - you can either set their onclick attribute, or attach an event handler to them.

Prashant, Robertjan: Right now there aren't any plans to integrate this into an official offering. What I do know is it isn't going to happen in the Orcas timeframe for sure.

Eric, Andrew, et. al: Thanks.

Dion: There are some runtime constructs that aren't available in asp.net ajax, but are in the script# runtime. Until those show up in asp.net ajax, both will need to co-exist. The choice of which runtime one chooses is up to the developer. Yes, it would be easier to support just one... but at least for now there are two... there are a few things I like about the Script# framework, that I'd like to see go forward... anyway, who knows what the future will bring... maybe over time there will be even more convergence, but even if theres agreement on a plan, there is a matter of relative timing as to how soon and when ideas can start being incorporated into the official product. :-)

Jesse

Posted on 5/23/2007 @ 8:06 AM
You amaze me.. I should probably read the ReadMe but I was wondering if there is a list of what classes can be used in Script#? For example, can I create control that uses a preexistring generic collection to populate a menu control? I can't wait to try out Script# this weekend, been meaning to forever, but no time but after seeing what it does with Ajax now I am determined:)

Nikhil Kothari

Posted on 5/23/2007 @ 8:31 AM
Jesse - you can look at what classes are available by browsing the assemblies in reflector - for the atlas mode, that is aacorlib.dll, MicrosoftAjax.dll, and aaagctrl.dll... and for the script# runtime, its ss*.dll (several). This is one of the nice things thats enabled for free using the script# model.

Currently generics aren't supported, but that is a key thing on the list of future possibilities.

The readme does three things: intro to what you can build with script# and whats in it, overview of how it works, and a set of patterns for how something in script is achieved, or how something in managed code is compiled to script. It doesn't have an intro to using the atlas mode in a dedicated section, but this blog post does that. I'd highly recommending doing a quick pass over the document to get a high-level sense for things.

Simon FERQUEL

Posted on 5/23/2007 @ 12:47 PM
Is there any chance that Script# would become an Open Source project hosted by CodePlex for example (just like the Ajax Control Toolkit)?
I would enjoy to contribute to this great project. There are many features to add, and many things to fix, and it is a shame that only one person is working on it...

Deepak Chawla

Posted on 5/24/2007 @ 1:47 PM
Nikhil, Just downloaded the Script# version 0.3.0.0

Started by creating the Script# template and get the following errors.

The file ssfx.UI.Core.dll could not be found within the project templates. Continuing to run, but the results project may not build properly.

And the same for:

ssfx.UI.Core.xml
ssfx.UI.Core.js
ssfx.UI.Core.debug.

Any ideas what 's missing from the setup kit

Nikhil Kothari

Posted on 5/24/2007 @ 2:26 PM
Simon: No plans right this moment, about putting this on codeplex. Perhaps you can contact me offline via my contact form, and we can discuss some ideas about what you'd like to do.

Deepak: Looks like I slipped in a bad project template - essentially there isn't an ssfx.UI.Core.dll anymore - some of the functionality is in ssfx.Core.dll, and some of the functionality (specific controls and behaviors) is in ssfx.UI.Forms.dll.

Deepak Chawla

Posted on 5/25/2007 @ 1:19 AM
Nikhil, are we likely to have an updated setup kit soon?
Would be a nice tool to play over the long weekend.

Thanks

Nikhil Kothari

Posted on 5/25/2007 @ 6:51 PM
Deepak, sorry not in time for the weekend... but that shouldn't block you... you simply need to remove the reference to ssfx.UI.Core.dll in your project, and add the right ones as listed above.

Steve Owens

Posted on 5/26/2007 @ 4:47 PM
"Prashant, Robertjan: Right now there aren't any plans to integrate this into an official offering. What I do know is it isn't going to happen in the Orcas timeframe for sure."

Is it possible to integrate Script# into Orcas?

Bo

Posted on 5/27/2007 @ 6:47 AM
This looks really great!
When I tried to connect to your project site to give it a try I got a timeout. :( Is it down?
I guess it is under heavy load...

GLM

Posted on 5/28/2007 @ 9:06 AM
Since project site doesnt work i'll post this here

I've done my first steps throght Script # with the latest version and I'm trying to write a gadget right now.

The thing I've done is quite simple: It has a text box, in the code, I get a reference to it take its value add 1 to it and set it back (just test code)
The thing is ive attached this event to both OnDock and OnUndock events of gadget it is happening once for OnUndock but it is happening twice for Ondock. Did I miss something here?

Also I've tried to debug this script, I attached the debugger to the sidebar and set a breakpoint on the .debug.js but it didn't stop.

Just to add something to the post, I build myself a post build event to install the gadget to the sidebar do you have any better idea?

Thank you. Bye

Nikhil Kothari

Posted on 5/28/2007 @ 3:01 PM
Steve: You should definitely be able to use Script# if you have orcas installed.

Bo, GLM: The site is back up...

GLM: No idea, but it seems the sidebar is itself raising the event twice, since you're working directly against the sidebar API. Make sure your event handler is not being attached twice, I guess. As far as debugging, first make sure its the right sidebar.exe process you are attaching to, and secondly try Debug.Fail and see if you can attach from the prompt that comes up. Also make sure script debugging is not disabled (by going through the IE options dialog).

Zack Owens

Posted on 5/29/2007 @ 3:26 AM
Is there any way for this to be done in VB? I'm sure there is a way :). If there is, this might become a really popular tool in the ASP.NET AJAX famework.

Chears,
Zack Owens

GLM

Posted on 5/29/2007 @ 6:17 AM
Well, as Debug.Fail didn't work I realised it wasn't loading .debug.js version of the scripts (i just realized this must be hand done) The references are at gadget.htm
Thanks for the help. I'll be posting this on the site.

Simon FERQUEL

Posted on 5/29/2007 @ 9:48 AM
I wrote a tutorial about using Script# and ASP.NET AJAX (with some tricks about client-behavior ASP.NET controls support for VS / Expression WEB designer) . Maybe it can interest you:
blogs.labo-dotnet.com/simon/archive/2007/05/29/17156.aspx

Michael Norton

Posted on 5/29/2007 @ 9:49 AM
How do you implement global variables using Script #?

Thanks,

Michael

Nikhil Kothari

Posted on 5/30/2007 @ 6:40 AM
Michael, I would suggest creating a global method that returns the global variable and then you can create a c# class for representing the global method (look at the readme for how to create a class representing existing script APIs, and the use of [GlobalMethods] to create a class representing global methods). Alternatively, you could also do Type.GetField(typeof(Window), "name_of_global_var") which results in generated script like window.name_of_global_var - global variables in script are accessible as members of window, and hence this would work as well.

Stephen Potter

Posted on 5/30/2007 @ 2:35 PM
Another wonderful step in this great tool. We used Script# when developing our new ASP.NET Grid product. The beta is being wrapped up as I write this. Check it out at www.softwarefx.com/gridfx. Script# provided a massive development boost for us. The ASP.NET AJAX integration is exactly what I needed. Thanks for everything!
- Steve Potter

Muhammad Mosa

Posted on 5/31/2007 @ 3:33 AM
Thank you so much for Script#. My Question is, how can I access Function._validateParams global method from Script#?! or this is not supported?!

Muhammad Mosa

Posted on 5/31/2007 @ 5:39 AM
Hey again, my issue was that I want to validate function arguments and here is how I resolve it.

object args = Script.Eval("arguments");
object param = Script.Eval("[{name: 'value', type: Number}]");
object ex = Type.InvokeMethod(null, "Function._validateParams", args, param);

Do you have any recommendation about that?! I tested this and it was working fine, even when and exception occur I was able to get ex.description.

Nikhil Kothari

Posted on 5/31/2007 @ 8:38 AM
Function._validateParams is an internal method, not meant for public consumption (hence not present in MicrosoftAjax.dll). However a better way to call it might be (I think it should work... though I haven't tried it):

ArrayList argInfo = new ArrayList();
argInfo.Add(new Dictionary("name", "value", "type", typeof(Number));
Type.invokeMethod(typeof(Type), "_validateParams", typeof(Arguments), argInfo);

Muhammad Mosa

Posted on 5/31/2007 @ 10:59 AM
Yes your idea worked, but I cannot use Add method in ArrayList Directly I should use
ArrayList.Add(argInfo, new Dictionary("name", "value", "type", typeof(Number));

Thank you for the idea.

I've tried to use partial class and separated my code into 2 files, but the complier didn't accpet that?! it is not an important issue, but do you have any idea why?!

Nikhil Kothari

Posted on 5/31/2007 @ 12:27 PM
Yeah ... the ArrayList.Add method is static because thats the way it is in Microsoft AJAX... its an instance method in the Script# framework/runtime...

Partial classes are currently not supported by the compiler. I will look into either supporting them, might require more time... and/or in the short term actually flag that as a compilation error.

AJ Croteau

Posted on 5/31/2007 @ 12:41 PM
Hey Nikhil,

This looks great and im really looking forward to learning this in the near future.

However, I'm having trouble with 0.3.0.0 because of a problem listed above where, when you create a new website, you get a couple of errors, can't find the following references: ssfx.UI.Core.dll, .Core.xml, .Core.js, and .Core.debug. Now you said that to get around this you need to remove the references and add the right ones. I'm confused. I don't see a reference to the ssfx.UI.Core.dll in the new website project anywhere and also what right ones, what are the "right ones"? The only reference I do see is one to a "nStuff.ScriptSharp.Web".

Thanx, AJ

Muhammad Mosa

Posted on 5/31/2007 @ 3:56 PM
I want to use Function.createCallback method?! I'm not able to pass a method to this function?! Shall I create a delegate first and pass the delegate to the method?!

Ankit Kedia

Posted on 6/29/2007 @ 10:49 PM
your blogs a re realy helpful
The discussion on this post has been closed. Please use my contact form to provide comments.