Why Ajax.NET Professional is using the __type property?
Ajax.NET Professional 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:
[AjaxMethod]
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 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:
See more examples on how to use .NET data types as return and argument values at http://munich.schwarz-interactive.de/datatype.aspx. New example of above problem comparing Atlas with AjaxPro at http://berlin.schwarz-interactive.de.