wwHoverWindow Method Callbacks


Home | Reset Page | Page generated at: 8/30/2008 2:15:20 AM

The following examples call methods on the running ASPX page. The methods on the server are accessible once marked with [CallbackMethod] attribute. Once set the wwMethodCallback control will expose these methods either via manual client code or via an auto-generated proxy object. The Proxy maps the signatures of the methods so you can do:

            Proxy.Helloworld("Rick",HelloworldCallback,OnPageError);
            Proxy.AddNumbers(15,12,AddNumbersCallback,OnPageError);
Results are sent back to a callback javascript client handler. Parameters and Result values are passed as JSON values between client and server which is a lightweight way to pass simple and complex data. To see what's happening I recommend you hook up an HTTP viewer like Fiddler to watch the HTTP traffic.


Mandatory Hello World Method
protected string Helloworld(string Name)

 Enter your name:


Number Addition
protected decimal AddNumbers(decimal Num1,decimal Num2)   (try entering an invalid number)

+

=


Server Exception Marshalling
protected string ThrowException(string Value)     (checked checkbox causes a server Exception)





 
This sample demonstrates using the wwMethodCallback control to make callbacks to the current page.
The control creates a page proxy instance that maps the server methods and simply lets you call these
server methods from the with code like:

Proxy.Helloworld("Rick",OnSuccess,OnFailure);

Callbacks are asynchronous and the callback handler is called on success with the result value. On
the server you simply implement a method on the Page (or any user or custom control or HttpHandler)
and the control manages the rest.

1. Create a method on the server with standard parameters
2. Mark up the method with the [CallbackMethod] attribute
3. Hook up your clientside code with code like this:
   Proxy.Helloworld(document.getElementById('txtName').value,OnSuccess,OnFailure);
    (Parameters: ControlId,Method name,Parameter1,Parameter2...n,CallbackMethod)
4. Implement the callback method which receives a result value or object.

Values are passed back from the server as typed values using JSON, so you can pass back strings, dates, number,
bools as well as many objects, including Arrays, IList based objects,  DataTables and DataRows. You can also pass
typed values and objects back to the server. Currently simple types, simple hierarchical objects and array and IList
style collections are supported. DataTable/DataRow are not support for return trips at this point.

Finally this example also demonstrates how an exception is returned from the server. Check the Throw Exception
checkbox, then click on the Pass Entity button. When checked the server code throws an explicit exception which
is returned as a special Exception object you can check for. Typically your client script callback handler checks
for a null result and can check for Result.IsCallbackError to see if an error occured on the server. Result.Message
returns the error message.