Ajax.NET Professional and the "missing" context

Tags: .NET, AJAX, Ajax.NET, ASP.NET

I had done a lot of changes to the JavaScript methods. With the new version I had removed the context that you could provide to have something like a "this" context.

-- Before --

function doTest1() {
  var context = document.getElementById("input1");
  AjaxNamespace.AjaxClass.MyMethod(1, 2, 3, doTest1_callback, context);
}

function doTest1_callback(res) {
  res.context = res.value;
}

doTest1();   // invoke the method

-- Using Ajax.NET Professional --

function myClass() {}

myClass.prototype.doTest1 = function() {
  this.inputEle = document.getElementById("input1");
  AjaxNamespace.AjaxClass.MyMethod(1, 2, 3, this.doTest1_callback.bind(this));
}

myClass.prototype.doTest_callback = function(res) { 
  this.inputEle = res.value;
}

var c = new myClass();
c.doTest1();    // invoke the method

There are more ways to implement "classes" on the client with a context. Another way is to inherit from the AJAX wrapper class:

function myClass = Class.create();
myClass.prototype = (new AjaxNamespace.AjaxClass()).extend({
  doTest1: function() {
    this.inputEle = document.getElementById("input1");
    this.MyMethod(1, 2, 3, this.doTest1_callback.bind(this));
  },
  doTest1_callback: function(res){
    this.inputEle = res.value;
  }
});

var c = new myClass();
c.doTest1();    // invoke the method

Any feedback?

No Comments