| West Wind Web Connection 5.00 |
Class wwWebAjax
|
The wwWebAjax control provides an easy to use AJAX style control that lets you call Server side URLs and code without re-submitting the entire page. You can use this control to retrieve server content and update the current page with the content retrieved.
The Control provides the following features:
The control manages all aspects of retrieving the data and displaying it on the client including placement and managing page scroll off and activation and hiding.
You can call back to the currently running page and call methods on that page. You can do so with somewhat natural syntax which looks like this in script code:
CallMethod('LookupPanel','Helloworld','Parm1',Helloworld_Callback);
The first parameter is the name of the AJAX control, the second the method, followed by a list of parameters and a final parameter that is a Callback method that gets called when the server is done processing. Calls are asynchronous.
What's cool about this is that you can return simple values like string and HTML fragments easily, but you can also return numbers dates and even cursors and objects. THe control returns data using the JSON protocol which is a JavaScript compatible string serialization format. What this means is that you can return a Fox cursor and get an object on the client side that looks like this:
Result.Rows[1].FIRSTNAME
The cursor is turned into an object with a Rows array and fields that match the field of the table with the proper types. So dates are returned as JSCript dates.
Currently the JSON support is only down from the server - parameters sent up are always sent as strings. The reason for this is that FoxPro doesn't provide runtime type information that makes it difficult to dynamically create the types - you'd basically have to sniff all types. I have some ideas on how to make this work, but this is too sketchy to try and get into the initial release.
However - and this is an important however <g> - the control can post current form data back to the server on a callback. The request goes through the standard page cycle so it even assigns the properties right back into the appropriate controls with the current callback values. This means if you have a server control on the form and you changed it on the client you can access the control with:
this.txtName.Text
inside of the callback and actually get a current value so you don't have to use explicit Request.Form() calls. Since data has to be pulled out of form controls anyway you might as well do it on the server if the form data isn't prohibitively large.
The deserializer works with most simple objects including nested objects and nested arrays and IList implementing collections. The idea is that you can pass an object from the server to the client side, manipulate the object and pass it back. The control creates a client side wrapper object for the server methods, so you simply call the method with the same parameters that exists on the server, plus a Callback_Handler pointer to a function that handles the request. The function returns a single value that will be the result, or an exception object you can check for. Note that DataSet/Table/Row are not support for serialization back to the server!
Multiple Controls
You can drop multiple copies of the control on the page, so if you want multiple hover windows you'd assign one to each of these controls. The Urlbased Callbacks too map one callback to one handler. Page level method callbacks only require one control on the page for all the methods that are published (you might need multiples if you have multiple simultaneous callbacks going).
Some other useful features:
| Member | Description |
|---|---|
AdjustWindowPosition | Determines if the Window position is adjusted if the panel scrolls off the page |
AllowedPageMethods | A comma delimited list of methods that can be called via remote calls when EventHandlerMode = "CallPageMethod". If empty any method can be called. |
ClientEventHandler | The client event handler that is called when the request fires. Typically this value can be left blank. |
IsCallback | Determines whether the current request is a Callback for the control. Useful if you want to route a callback through special handling. |
NavigateDelay | The delay before the client code fires a callback request. |
PanelOpacity | Optional Panel Opacity if the panel is displayed. Value is given as a fraction percentage (.10 = 10%). Set the value to -1 to indicate no opacity setting. |
PanelShadowOffset | Optional offset for the Shadow if a shadow is displayed. Specify 0 for no shadow. |
PanelShadowOpacity | Optional Panel Shadow Opacity. Only applies if a ShadowOffset is set. Value is given as a fraction percentage (.10 = 10%). Defaults to .30. |
PostBackFormName | Name of the form that values are collected from and posted back to the server. If not specified the first form is used. |
PostBackMode | Determines how PostData is sent back to the server |
ScriptLocation | If the ScriptLocationType is external, this is the URL to the script file. We recommend you use an application relative path starting with the ~/ base path. |
ScriptLocationType | Determines how the JavaScript support library file is loaded. |
ServerUrl | The URL that is to be accessed on the server. Applies to ShowHtmlAtMousePostion, ShowHtmlInPanel and CallExternalPage modes. |
Source File: webcontrolsextended.prg