The World’s Leading Microsoft .NET Magazine
   
 
The .NET Addict's Blog

My Top Tags

                                                           

My RSS Feeds








Latest Diggs - Programming

Computers Blogs - Blog Top Sites

Site Hits

Total: 2,795,178
since: 19 Jan 2005

Volta is to Ajax what Tums is to my Stomach

posted Wed 30 Jan 08

This is a deliberately oversimplified example. I typically hate oversimplified examples, but I think most people reading this blog will be able to extrapolate the useful bits from this sample out into practical uses. Also, Volta is still a CTP and subject to radical change in the future, so I'm not so worried about conforming to best practices yet, since there are none :)

In a typical Ajax application, your goal is often to have the user click something. In response, JavaScript goes out and (through the magic of XML HTTP Requests) obtains data and potentially modifies data on a server as well. Using the returned data, the JavaScript can then directly manipulate the HTML DOM to make it appear to the end user as though things just dynamically happened in a manner very similar to a traditional desktop application.

While there are lots of libraries that enhance and abstract on top of that functionality, that is essentially the core of what Ajax is and why it is so popular. The problem is that everybody's got their own flavor of Ajax library, and some of them require you to write a truckload of JavaScript. Most of the tools for dealing with Ajax, even the most advanced ones, still require the developers to think in terms of multiple paradigms, multiple tiers, and potentially even multiple languages and/or development environments - all just to get a little change to happen to a page without doing a visible refresh. Not worth it, IMHO. I've got better things to be doing, like building application functionality, not twiddling with silly little JavaScript semantics.

So, let's say I have a button that I want to trigger the revealing of a hidden <div>. Sure, it's simple to do in JavaScript, but what I want to show you is how Volta let's you do it all in C#. Here's my contrived HTML:

<body>
    Hello. This is Ajaxy!
   
    <button id="btnClick">Click Me to Reveal the hidden text!</button>
    <div id="hiddenText" style="visibility:hidden;">
        <b>This is a hidden message!</b>
    </div>
</body>

So, if I started littering this page with some JavaScript, I could get the div to appear. But, what if I wanted the contents of the div to contain a weather report from some remote web service, complete with gradients and images, etc. Now, what if I want to _debug_ that code, and what if I want that code to be strongly typed and unit testable?? Screw JavaScript, it's not going to get the job done.

Here's the code for my Volta page. You can see it grabs references to HTML DOM elements, sets up a purely C# event handler, and manipulates the DOM directly - all in C#, and no mention of browser cap checking, no mention of tier, and no mention of JavaScript. It's all just pure C# from end to end.

public partial class VoltaPage1 : Page
    {
        private Button _clickButton;
        private Div _hiddenTextDiv;
        public VoltaPage1()
        {
            InitializeComponent();
            _clickButton = Document.GetById<Button>("btnClick");
            _hiddenTextDiv = Document.GetById<Div>("hiddenText");
            _clickButton.Click += new HtmlEventHandler(_clickButton_Click);
        }
        void _clickButton_Click()
        {
            _hiddenTextDiv.Style.Visibility = "visible";
        }
    }

When you run this app, and it launches IE pointing at the Volta web server, you can click the button and see it dynamically reveal the contents of the hidden div. Obviously nobody gives a crap about applications that reveal hidden divs. However, if you want absolute control over your DOM, and you want to leverage your C# experience and be able to designate certain blocks of C# code as running on the server tier without worrying about the busywork of getting around the same-origin policy, then Volta might actually be what you're looking for.

If you can think of some samples that are more practical than this (I wanted to do this as an intro before doing more involved samples), please let me know and I'll see what I can come up with.

tags:          

links: digg this    del.icio.us    technorati    reddit




1. James Gregurich left...
Wed 30 Jan 08 1:01 pm

is "VoltaPage1" supposed to run on the client side?


2. Kevin Hoffman left...
Wed 30 Jan 08 1:03 pm

Yes, in the default Volta configuration, Volta will recompile the page class and dump the whole thing in JavaScript to the client. You can use the "RunAtOrigin" attribute to designate that specific C# classes run behind a service facade and will remain on the server.


3. James Gregurich left...
Wed 30 Jan 08 1:46 pm

interesting concept


4. grrrr left...
Thu 31 Jan 08 12:08 pm

"interesting concept" Yes it is and you have to thank google for that. It is a gwt clone in .net.


5. Kevin Hoffman left...
Thu 31 Jan 08 12:11 pm

GWT clone in .NET? That's a pretty narrow-minded thing to imply. GWT is solely focused on JavaScript and in-browser paradigms. I can use tier-splitting to take a C# class in my Windows Forms or WPF application and shove it off to run as a back-end service. I can multi-tier-split to cascade services behind subsequent firewalls. GWT isn't even a recompiler. Before you compare GWT to Volta, you should experiment with Volta first. GWT is, as its name implies, a Web Toolkit. Volta is a tier-splitting IL-to-IL recompilation tool that just happens to have JavaScript as one of the target tiers.


6. grrrr left...
Fri 01 Feb 08 11:59 am

I think you do not know what gwt is when you say "GWT is solely focused on JavaScript " also when did "recompiler" become a computer science term? Gwt is indeed also a compiler with as target javascript.


7. Kevin Hoffman left...
Fri 01 Feb 08 12:05 pm

I have played with GWT before. I never said that "recompiler" was a computer science term, it's just some word I pulled out of my nether region. The fact that this blog is not being reviewed by grammar police allows me to do such things. I realize that GWT targets JavaScript... but that's _all_ it targets. GWT doesn't allow me to take a Windows application built as a single monolith and then declaratively split that application into a smart client and a collection of services that can be distributed across multiple locations. That is the difference I was trying to clear up - on the surface GWT and Volta look similar, but Volta is far more generalized as a tier-splitting tool that can be used for WinForms, WPF, or Web applications.


8. grrrr left...
Sat 02 Feb 08 5:24 am

I don't want to be the grammar police. I do not even speak english that well but I am a bit tired of those vendor invented semi-technical/marketing terms like recompiling or tier-splitting. The basic idea is exactly the same minus some implementation details and the marketing speak. I must admit that maybe clone was a to strong word.


9. Ben Zamora left...
Sat 02 Feb 08 12:27 pm :: http://zinovate.com/weblog/

Kevin, I'm with you big time. Volta is a big step and tier splitting is way more than a marketing tem. I bet volta and silver light will be a great comb as well... at some point.


Tag Related Posts

Cappuccino, Objective-J, and You

Wed 10 Sep 08 6:14 P GMT-05

NYC SharePoint Developer Needed

Mon 12 May 08 12:09 P GMT-05

Scott Guthrie Updates the ASP.NET MVC Roadmap

Wed 13 Feb 08 3:49 P GMT-05
tags:    

Volta is to Ajax what Tums is to my Stomach

Wed 30 Jan 08 4:11 P GMT-05

ASP.NET 3.5 Extensions Preview Released

Mon 10 Dec 07 2:10 P GMT-05

Microsoft unveils an MVC framework for ASP.NET

Mon 08 Oct 07 12:58 P GMT-05
tags:      

Microsoft Volta - just another codename?

Wed 11 Jul 07 2:43 P GMT-05
tags:        

My Appearance in the RIA Shootout on sys-con.tv

Tue 05 Jun 07 11:41 A GMT-05
tags:              

ASP.NET Ajax v1.0 Beta

Fri 27 Oct 06 6:17 P GMT-05
tags:      

ASP.NET vs Ruby on Rails : Round 2 (Agility)

Thu 05 Oct 06 11:02 A GMT-05
tags:                      

ASP.NET vs Ruby on Rails : Round 1

Wed 04 Oct 06 1:37 P GMT-05
tags: