Script#, al igual que Google Web Toolkit, permite generar código javascript, utilizando en este caso cualquier lenguaje compatible con el .NET Framework.
using System;
using ScriptFX;
using ScriptFX.UI;
namespace HelloWorld {
public class Demo : IScriptlet {
private Button _okButton;
private XMLHttpRequest _request;
public void Start() {
_okButton = new Button(Document.GetElementById("okButton"));
_okButton.Click += new EventHandler(this.OnOKButtonClick);
}
private void OnOKButtonClick(object sender, EventArgs e) {
Callback completedCallback = new Callback(this.OnRequestComplete);
_request = new XMLHttpRequest();
_request.Onreadystatechange = Delegate.Unwrap(completedCallback);
_request.Open("GET", "Hello.ashx", true);
_request.Send(null);
}
private void OnRequestComplete() {
if (_request.ReadyState == 4) {
_request.Onreadystatechange = Function.Empty;
Window.Alert(_request.ResponseText);
}
}
}
}
En la página de demostración, lo único que se tiene que hacer es registrar la clase "HelloWorld.Demo".
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Demo Script#</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" id="okButton"
value="OK" />
</div>
<nStuff:Scriptlet runat="server"
ScriptAssembly="HelloWorld"
ScriptletType="HelloWorld.Demo" />
</form>
</body>
</html>
// Handler.ashx: Se encarga de procesar la petición.
using System;
using System.Web;
public class HelloHandler : IHttpHandler {
public bool IsReusable {
get {
return true;
}
}
public void ProcessRequest(HttpContext context) {
HttpRequest request = context.Request;
HttpResponse response = context.Response;
string greeting = String.Empty;
string name = request["name"];
if (!String.IsNullOrEmpty(name))
{
greeting = "Hello " + HttpUtility.HtmlEncode(name) + "!";
}
else
greeting = "Hello from server";
greeting += " - Server time: " + DateTime.Now.ToShortTimeString();
response.ContentType = "text/plain";
response.Write(greeting);
}
}
<?xml version="1.0"?>
<configuration>
<system.web>
<pages>
<controls>
<add tagPrefix="nStuff" assembly="nStuff.ScriptSharp.Web" namespace="nStuff.ScriptSharp" />
</controls>
</pages>
</system.web>
</configuration>
Pueden descargar el compilador de Script# desde http://www.nikhilk.net/Content/Samples/ScriptSharp.zip o ver un video demostrativo en http://www.nikhilk.net/Content/Video/ScriptSharpIntro.wmv