Why Ajax.NET Professional is using the __type property?

Michael Schwarz on Friday, July 7, 2006

Ajax.NET Professional [1] is using attributes, there is no need to inherit from special pages or include dummy web controls to do all the job, there is no need to write special source code. Any .NET assembly can include classes with AjaxMethods that can be used in your ASP.NET web application.

Some months ago I had a question from a web developer that is using a separate assembly for all the business logic (data access layer). He was using this library in a windows application and want to use it with ASP.NET and Ajax.NET Professional, too. He simply added the AjaxMethod attributes, re-compiled it and it was working. The assembly includes some methods where the client will get a list of Person instances, see following example:

public class Person
public string FirstName;
public int Age;

[AjaxMethod] public static Person GetPersonFromDatabase(int id) { return DAL.GetPerson(id); }

The developer added some more Person classes that inherit from the common Person class above: 

public class MyPerson : Person
public string FamilyName;
public DateTime Birthday;

And using Ajax.NET Professional he was able to use the returned values again as argument for following method, which will save the person data as XML on the web server:

public static SavePerson(Person p)
if( p is MyPerson )
// if MyPerson do something here

DAL.SavePerson(p);    // where DAL.SavePerson accepts Person }

The big benefit using Ajax.NET Professional is that you will get any .NET class to the client-side JavaScript code, and that you will be able to use it as arguments, too.

The same this is working if you are using List<object> or ArrayList which does not include a type for the items in the list.

Yesterday evening I tried this with Atlas [2] and WebServices, but it was not working. In debug mode I got the message below when using an MyPerson instance as argument value for the SavePerson method:

The type IPerson does not have a public property or field named Birthday

See more examples on how to use .NET data types as return and argument values at http://munich.schwarz-interactive.de/datatype.aspx [3]. New example of above problem comparing Atlas with AjaxPro at http://berlin.schwarz-interactive.de [4].