This example demonstrates Method Callbacks into the same page with the wwMethodCallback control. By using server side methods marked up with [CallbackMethod] you are allowing client side code to call these server methods and return the results as typed values or objects via the JSON encoding format. Client side code fires requests against the server with code like this: CustomerCallback.GetCustomerEntity('ALFKI',GetCustomerRow_Callback,OnPageError);
The control returns the results of the server method calls via JSON serialization, which attempts to maintain the object structure and typing across the callback from client to server and back.
In this sample all data is retrieved via Callbacks. The DataTable is returned for the listbox and a Customer Entity object for the population of the Customer data fields. The data can then be updated on the page and is saved by calling the SaveCustomer() method which takes no parameters. Rather than passing the Entity back (which is possible) the server side code instead accesses the POST buffer and ASP.NET server control values to retrieve the values and store them onto the server side entity object which is then validated and saved. The server side code fires exceptions on errors - the exceptions are also serialized into an Exception object and returned to the client. The client can check for an error flag - if (Result.IsCallbackError) to determine error status. This works for operational failures as well as Application level errors such as business rule validations. For example, if you leave out the name or company fields a validation error is triggered which is sent back to the client.