Wednesday, March 28, 2012

Calling a server side method.

My experience lies with Ajax.net. I need to call a method passing parameters back on the server. What ATLAS methodology should I do?

Imagine the scenario where I have a ordered list and I have the option client side to change the order. After each order change (the client UI is modified), I need to just touch a method on the server. I don't need any response or updates back.

I would like to do something like this

function OnItemMoved( first, second )
{
AltasCall.MovingObject.MoveItems( first.ID, second.ID );
}

Hi,

a PageMethod seems appropriate for your scenario. Basically you have to add the [WebMethod] attribute on your server method (you have to declare this method in your Page class), make it public and then you will be able to call it on client side through the PageMethods namespace:

function OnItemMoved( first, second )
{
PageMethods.MyMethod(first, second);
}

I appreciate it greatly, works like a charm.

Do you know if it is possible to call another method outside the Page class's scope? This is library code, and I don't want to force the end user to declare this method on all their pages.


billrob458:


Do you know if it is possible to call another method outside the Page class's scope?


At the moment the methods must be put in the Page class. One solution to your problem would be to wrap the library method with a WebMethod and put it in a base class that inherits from Page. The other pages will then be derived from the base class.
Another solution would be to expose the reusable method as a web service - which can act as a wrapper for your library code. Then you can make the calls to the webservice from anywhere.

No comments:

Post a Comment