TActiveButton

TActiveButton is the active control counter part to TButton. When a TActiveButton is clicked, rather than a normal post back request a callback request is initiated. The OnCallback event is raised during a callback request and it is raise after the OnClick event.

When the ActiveControl.EnableUpdate property is true, changing the Text property during a callback request will update the button's caption on the client-side.

Since the OnCallback event is raised only during a callback request, the OnCallback event handler can be used to handle logic specifically related to callback requests. The OnClick event handler is raised when ever the button is clicked, even if javascript is disabled.

The following example the use of both the OnClick and OnCallback events of an TActiveButton.

TActiveButton Class Diagram

The class diagram for TActiveButton is illustrated in the figure below. Most active control that can perform callback request have a similar structure.

class="figure" alt="TActiveButton class diagram" title="TActiveButton class diagram" />

TActiveButton is an extension of TButton and implements two additional interfaces ICallbackEventHandler and IActiveControl. The TActiveButton contains an instance of TBaseActiveCallbackControl available through the ActiveControl property of TActiveButton. The following example set the callback parameter of the TActiveButton when a callback request is dispatched.

<com:TActiveButton Text="Click Me" OnCallback="button_callback" ActiveControl.CallbackParameter="value" />

In the OnCallback event handler method, the CallbackParameter is available in the $param object.

public function button_callback($sender, $param) { echo $param->CallbackParameter; //outputs "value" }

Adding Client Side Behaviour

With in the ActiveControl property is an instance of TCallbackClientSide available as a property ClientSide of TActiveButton. The ClientSide property contains sub-properties, such as RequestTimeOut, and client-side javascript event handler, such as OnLoading, that are used by the client-side when making a callback request. The following example demonstrates the toggling of a "loading" indicator when the client-side is making a callback request.

<com:TClientScript PradoScripts="effects" /> Loading... <com:TActiveButton Text="Click Me" OnCallback="button_callback" ActiveControl.CallbackParameter="value" > <prop:ClientSide OnLoading="Element.show('callback_status')" OnComplete="Element.hide('callback_status')" /> </com:TActiveButton>

The example loads the "effects" javascript library using the TClientScript component. The ClientSide.OnLoading property value contains javascript statement that uses the "effects" library to show the "Loading..." span tag. Similarly, ClientSide.OnComplete property value contains the javascript statement that hides the "Loading..." span tag. See TCallbackClientSide for further details on client-side property details.