5,696,038 members and growing! (17,668 online)
Email Password   helpLost your password?
Web Development » Ajax and Atlas » Atlas     Intermediate License: The Code Project Open License (CPOL)

Ajaxion - Ajax without javascript: WS calls, xml, drag'n drop, controls, binary image retrieval, etc

By Radu D.

An article about how to keep Ajax simple
Javascript, XML, C#, HTML, Windows, .NET, ASP.NET, WebForms, Ajax, VS2005, Visual Studio, Dev

Posted: 7 Mar 2007
Updated: 9 Mar 2007
Views: 30,819
Bookmarked: 40 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
21 votes for this Article.
Popularity: 5.38 Rating: 4.07 out of 5
1 vote, 4.8%
1
0 votes, 0.0%
2
2 votes, 9.5%
3
1 vote, 4.8%
4
17 votes, 81.0%
5
Screenshot - Screenshot.jpg

Ajax without Javascript ... don't believe it ... it's just "marketing" (haha). Another understanding would be "keep Javascript simple"... unless you have no choice. The best productivity and results are based on understanding. Ajax and web applications provide great advantages with understanding.

Background

I started Ajaxion to learn Ajax and I finished by using it to enhance a web page in an old web application, under maintenance. Many thanks to my good colleague, Marius Francu, that supported the first "real world" usage of Ajaxion.

The idea here is simple: there is an Ajaxion Javascript layer between the hosting page in the browser and the web server. The Ajaxion Javascript layer defines Ajaxion events enclosing Ajax calls to the web server. The web server runs some C# code (Java coming soon) to consume the Ajaxion events and their Ajax calls. The Ajaxion Javascript layer uses the object XMLHttpRequest to make HTTP calls to the web server. These calls are nearly the same POST or GET but in asynchrony with the normal host page life-cycle.

The meaning of Ajaxion is to build further Ajax-enabled controls, more than are currently used. Ajaxion is simple so it can be controlled / customized easily based on what someone could need, e.g. changes in the event monitoring, after that it can be used for specific controls.

Using the code

To use the code just download the sample that is appropriate for your version of .NET:

  • AjaxionTest_Net.1.1.zip works with VS 2003.
  • AjaxionTest_Net.2.0.zip works with VS 2005 (this was only imported, I hope to optimize it soon).

Further register the "AjaxionTest" web application into IIS, e.g. like this:

  • Go within the IIS hosting directory (e.g. "c:\Inetpub\wwwroot\").
  • Extract the .zip content; you should got the new directory "AjaxionTest" (e.g. "c:\Inetpub\wwwroot\AjaxionTest").
  • Register the new directory "AjaxionTest" as "AjaxionTest" web application (e.g. from the properties dialog of the "AjaxionTest" directory, shown by the IIS management console)

Once you have AjaxionTest on your IIS you can take advantage on the great debug power of Visual Studio.

A short guide for the code

Ajaxion relies in:

  • Ajaxion.js - that hosts a class like Javascript that initiates the Ajax calls.
  • *AjaxionEvents.js to define the Ajaxion events hosting the Ajax calls and their callback Javascript functions - used to update the host page's target HTML elements.
  • The C# class AjaxionEventConsummer that consumes the Ajaxion events with their Ajax calls.

How to get an Ajax enabled HTML element by using Ajaxion

Register the Ajaxion Javascripts to be used in the host page, e.g. see head of Default.aspx. Choose a HTML element's event to trigger the Ajaxion events:

onclick="ajaxion.Call('POST','AjaxCallbackWs.asmx/GetImageUrl', 
    'imageUrl', GetImageUrl);"

// or e.g. set the HTML event from the C# class of the host page 

// (be careful, both methods are used):


btnAjaxWsGetImgUrl.Attributes.Add("onClick",
    "ajaxion.Call('POST','AjaxCallbackWs.asmx/GetImageUrl',
    'imageUrl', GetImageUrl);");

Register the Ajaxion event (e.g. "imageUrl") and the callback function (e.g. "GetImageUrl") in the host page specific script (e.g. DefaultAspx_AjaxionEvents.js)

// Register Ajaxion event "imageUrl"

function GetEventParameters(eventId)
{
    ajaxion.ShowStatus('status', 'Processing...', 'coral');
    ajaxion.ShowStatusGif('statusGif', 'images/processing.gif');

    var parameters = '';

    switch (eventId)
    {
        ...    
        case 'imageUrl' :
            ajaxion.SetEventMonior('imageUrl', '');
            parameters = window.document.getElementById('dropDown').value;
            break;
        ...
    }
    return parameters;
}

// Ajaxion event "imageUrl" callback function.

// This updates the host page after the Ajax call for the 

// Ajaxion event was consumed.

function GetImageUrl()
{
    if (ajaxion.request.readyState == 4
        || ajaxion.request.readyState == 'complete')
    {
        window.document.getElementById('image').src = 
            ajaxion.request.responseText;
        window.document.getElementById('image').title = 
            ajaxion.GetParameters();
        EndAjaxionEvent();
    }
}

And, last but not least, the C# code to consume the "imageUrl" Ajaxion event (in this example there is a web service method):

[WebMethod]
public void GetImageUrl()
{
    Thread.Sleep(700); // Only to see status change, ajax effect


    try
    {
        string eventId;
        if (this.Context.Request.QueryString["imageUrl"] == null)
            eventId = "imageUrlIe6";
        else
            eventId = "imageUrl";

        AjaxEventConsummer callback = new AjaxEventConsummer(this.Context,
            eventId, "image/GIF");
        callback.ConsumeEvent("images/" + callback.Parameters);
    }
    catch (System.Threading.ThreadAbortException)
    {}
    catch (Exception ex)
    {
        FileLog.LogLine("\nException: " + ex.Message + 
            "\nTrace: " + ex.StackTrace);
    }
}

Points of Interest

The functionality demonstrated is (in the order it appears):

  • The exchange of a simple text between two text boxes, but the Ajaxion calls are targeted to the C# code of the host page or of other pages (be careful with the encapsulation).
  • An XML test, using a call to a web service. I like here (unless there is no choice) to handle XML in C# rather than something like Javascript. I value this more to stay as simple as possible - a simple layer to forward XML call parameters and some HTML as a call response.
  • An approach to start and monitor a thread running on the server.
  • Some image retrieval, also when you get the image binary e.g. from a database.
  • Some drag'n drop.
  • And, last but not least, a demo with a user control, the most appropriate usage of Ajaxion.

Hope this helps.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Radu D.


Software Developer
Occupation: Software Developer
Location: New Zealand New Zealand

Other popular Ajax and Atlas articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 10 of 10 (Total in Forum: 10) (Refresh)FirstPrevNext
GeneralThe code doesn't workmembertunminhein1:47 31 Oct '08  
General[Message Removed]membernompel10:00 6 Oct '08  
GeneralRadu is a girly girlmemberbug menot9:26 12 Mar '07  
GeneralRe: Radu is a girly girlmvptoxcct13:24 12 Mar '07  
Generalhow to implement ajax in ASP.Net 1.1memberM.Ramesh1:56 12 Mar '07  
GeneralRe: how to implement ajax in ASP.Net 1.1membernsimeonov5:37 12 Mar '07  
AnswerRe: how to implement ajax in ASP.Net 1.1 [modified]memberRadu D.23:53 12 Mar '07  
GeneralMessage Automatically Removedmemberbug menot11:46 7 Mar '07  
GeneralRe: hamemberbhaskar_priya19:10 8 Mar '07  
JokeRe: hamemberRadu D.23:55 12 Mar '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 9 Mar 2007
Editor: Sean Ewington
Copyright 2007 by Radu D.
Everything else Copyright © CodeProject, 1999-2008
FileMail | Advertise on the Code Project