To hook wwMethodCallback to a user or custom control:
Start by creating your control as usual and implement whatever features the control will have. The add your Callback methods that you want to expose to client callbacks and mark them up with [CallbackMethod] attribute as usual:
[CallbackMethod] public int Add(int x, int y) { return x + y; }
Then add the OnInit() code to add the wwMethodCallback control that will handle these callback methods:
protected override void OnInit(EventArgs e) { base.OnInit(e); // *** Add a MethodCallback control to this control // *** So we can make AJAX callbacks to this control wwMethodCallback Callback = new wwMethodCallback(); Callback.ID = this.ID + "_Callback"; Callback.TargetControlId = this.ID; this.Controls.Add(Callback); ... your OnInit() code this.RequestId = this.Context.Request.Form[this.ID + "_ReqId"]; if (this.RequestId == null) this.RequestId = ""; }
That's all it takes. The control takes care of the rest.
The control will generate a client side proxy of your class named with the same name as the control's ID (note it uses the ID not the UniqueID or ClientID - so you have to ensure uniqueness of your IDs!). You can then call the Proxy methods from your client side code. The control will automatically route the calls to the appropriate Callback methods and return the result to the client.
This mechanism works both with custom and user controls. For user controls you can also drop the wwMethodCallback control directly into the user control markup.