If you, like me, develop web applications, you got your hands all dirty with JavaScript.

Writing JavaScript isn't always easy, and with the new client-side features being added to the browsers, allowing rich applications to be developed, JavaScript is taking a great heat.

So we are now writing code in, at least, 3 flavours: C#, Html, and JavaScript.

But what if we could write C# code that generated JavaScript? 

This is where Script# enters the picture:

 

Script# brings productivity to Ajax and JavaScript development. Script# is a free tool that enables developers to author C# source code and subsequently compile it into regular script that works across all modern browsers, and in doing so, leverage the productivity and power of existing .NET tools as well as the Visual Studio IDE. Script# empowers you with a development methodology and approach that brings software engineering, long term maintainability and scalable development approaches for your Ajax applications, components and frameworks.

Script# is used extensively by developers within Microsoft building Ajax experiences in Windows Live, Office to name just a couple, as well as by a external developers and companies including Facebook. If you’re building Ajax-based RIA applications, you owe it to yourself to try Script# today and see if it can help improve your own Ajax development!

 

Script# is used by Microsoft, for instance, to generate the MicrosoftMvcAjax scripts that are available when we create a new asp.net MVC project.
 

scriptsharp1.png

 

Lets start with a simple example...

 

...of binding a click event to a button:
The previous code generates the following:

 

 

Notice that:
  • The code we made in C# is almost identical to the code generated;
  • All the client-side objects, like Window and Document, are available to C# code, so there is no new learning involved and with the benefit of compile time checks;
  • All the documentation added to the C# code is also added to the JavaScript (on the debug file);
  • We are working on a OO code on the client-side.
So, on our page we can now add the necessary script references:

 

 

We even got intellisense and the documentation helper. How cool is this?

 

Now, lets improve our code a bit by using jQuery. This is for me the best JavaScript framework:

 

jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript.

 

So lets create a new ScriptSharp scriptlet:

 

When we build, our new code will be added to the ScriptLibrary(.debug).js:

 

 

In the end...

 

This is a great tool to build JavaScript.
There are some small issues with this, like the lack of good documentation our closed source code. Although jQuery support was added with the latest drop, there's no support for the jQueryUI.

Last edited Sep 8, 2010 at 1:30 PM by brunofig, version 1

Comments

No comments yet.