ASPxCallback Class
A non-visual component that allows you to make a round trip to the server (send a custom callback request) and perform server-side actions. The component cannot update other controls in a callback.
Namespace: DevExpress.Web
Assembly: DevExpress.Web.v21.1.dll
NuGet Package: DevExpress.Web
Declaration
Remarks
The ASPxCallback control allows you to send callbacks from the client side and then process them both on the server and client sides.
Note
The ASPxCallback control cannot update any visual control on a web page. For this purpose, use the ASPxCallbackPanel control that serves as a container. Use the callback panel to send a callback to the server and update any control within the panel.
Create a Callback Control
Design Time
The ASPxCallback control is available on the DX.21.1: Components toolbox tab in the Microsoft Visual Studio IDE.
Drag the control onto a form and customize the control’s settings, or paste the control markup in the page’s source code.
Note
To properly function, DevExpress controls require that special modules, handlers and options are registered in the the Web.config file. Switch the Microsoft Visual Studio IDE to the Design tab to automatically update the Web.config file with the required DevExpress information.
<dx:ASPxCallback ID="ASPxCallback1" runat="server">
</dx:ASPxCallback>
Run Time
using DevExpress.Web;
...
protected void Page_Load(object sender, EventArgs e)
{
ASPxCallback callback = new ASPxCallback();
callback.ID = "ASPxCallback2";
Page.Form.Controls.Add(callback);
callback.ClientInstanceName = "cb";
callback.Callback += new CallbackEventHandler(ASPxCallback_Callback);
}
protected void ASPxCallback_Callback(object source, CallbackEventArgs e)
{
// your code
}
Client-Side API
Availability | Available by default. |
Client object type | |
Access name | |
Events |
Overview
Use the PerformCallback(parameter) method to send a callback to the server. The InCallback method allows you to get whether the callback is sent. Handle the CallbackComplete client event or the Callback server event to process the callback.
You can use the JSProperties property to send information from the server to the client.
<dx:ASPxButton ID="ASPxButton1" runat="server" Text="Get time from server" AutoPostBack="False">
<ClientSideEvents Click="function(s, e) { callbackControl.PerformCallback(); }" />
</dx:ASPxButton>
<dx:ASPxCallback ID="ASPxCallback1" runat="server" ClientInstanceName="callbackControl"
OnCallback="ASPxCallback1_Callback">
<ClientSideEvents CallbackComplete="function(s, e) {
document.getElementById('editorContainer').innerHTML = s.cpTextBox1;
textBox2.SetText(s.cpTime);
}" />
</dx:ASPxCallback>
<table id="formContainer">
<tr>
<td id="editorContainer">
<asp:TextBox ID="TextBox1" runat="server" Width="200px" ></asp:TextBox>
</td>
<td>
<dx:ASPxTextBox ID="ASPxTextBox1" runat="server" ClientInstanceName="textBox2" Width="200px" />
</td>
</tr>
</table>
protected void ASPxCallback1_Callback(object source, DevExpress.Web.ASPxCallback.CallbackEventArgs e){
ASPxCallback callbackControl = source as ASPxCallback;
string time = DateTime.Now.ToString("T");
TextBox1.Text = time;
callbackControl.JSProperties["cpTextBox1"] = ASPxCallback.GetRenderResult(TextBox1);
callbackControl.JSProperties["cpTime"] = time;
}