Tuesday, May 16, 2006

Cool Atlas information from Jeff Prosise

Yesterday we had a very interesting lunch and learn session on the topic of Atlas. The speaker was Jeff Prosise, co-founder of Wintellect. Jeff was an excellent speaker. I learned a lot in the little time that we had. Here is a breakdown of Jeff's presentation.

1. Introductions
Jeff started out the presentation with a brief overview of Atlas. Atlas is Microsoft's upcoming AJAX framework. It is only compatible with ASP.NET, so you have to serve it from IIS. It is also only compatible with .NET 2.0 and higher. There will be no backwards compatibility with .NET 1.x. I was under the impression that Atlas was a mostly server side technology. However, using the XML scripting language, you can do just about everything on the client side.

2. Ajax support already built into ASP.NET
Jeff demonstrated that there is already support for AJAX built into ASP.NET 2.0. You just have to do a little bit of coding to get it to work. Basically you implement the ICallBackEventHandler interface on your page and then grab a reference to the javascript function that you wish to return to. Here is a page and the code-behind that demonstrates using AJAX in an ASP page.
ASPX:

<html>
<head>
<script language="javascript" type="text/javascript">
function MultiplyByTwo()
{
var tb = document.getElementById("txtNumber");
var value = tb.value;
CallServer(value, "");
}
function DisplayResult(rValue)
{
document.getElementById("lblResult").innerHTML = rValue;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="txtNumber" type="text"> * 2
<input onclick="MultiplyByTwo();" value="=" type="button">
<asp:label id="lblResult" runat="server">>
</asp:label></div>
</form>
</body>
</html>



Code-behind:
public partial class _Default : System.Web.UI.Page, ICallbackEventHandler
{

protected string returnValue;

protected void Page_Load(object sender, EventArgs e)
{
string cbReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "DisplayResult", "context");
string callbackScript = "function CallServer(arg, context){" + cbReference + ";}";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServer", callbackScript, true);
}

#region ICallbackEventHandler Members

public string GetCallbackResult()
{
return returnValue;
}

public void RaiseCallbackEvent(string eventArgument)
{
if (!String.IsNullOrEmpty(eventArgument))
{
int arg = int.Parse(eventArgument);
arg *= 2;
this.returnValue = arg.ToString();
}
}

#endregion
}


3. Framework
When a page containing atlas controls is requested, Atlas sends a copy of its framework down to the client machine. The framework is written completely in javascript. Since most browsers cache javascript, the framework should only be downloaded once, instead of everytime you hit page with an Atlas control. Jeff also mentioned that the release version will contain a browser abstraction layer. This layer will be responsible for making sure your code runs correctly no matter what browser it is displayed in.

4. Clientside Focus
For the clientside, Jeff focused on Atlas' XML scripting language. Most of the examples used very little server side code. The framework parsed the script and generated the necessary javascript to perform the actions. Here is an example of some XML script that displays a panel when you click on a button.

<script type="text/xml-script">
<button id="showButton">
<click>
<setProperty target="panel" property="visible" value="true" />
</click>
</button>
</script>


5. Serverside Focus
For the serverside, Jeff showed off some "Extender" controls. Most noteable the MSN Earth control that hits the same servers as Windows Live Local. There isn't a lot of documentation out there for these, but they seem really cool.

No comments: