Back to Devexpress

The target 'X' for the callback could not be found or did not implement ICallbackEventHandler

aspnet-403749-troubleshooting-server-side-issues-target-did-not-implement-icallbackeventhandler.md

latest2.5 KB
Original Source

The target 'X' for the callback could not be found or did not implement ICallbackEventHandler

  • May 30, 2024
  • 2 minutes to read

Error Description

This error occurs for a parent control or its child controls if the parent control is created at runtime.

Solution

Follow the steps below when you create a control/WebUserControl at runtime:

  1. Use a control’s constructor or call the LoadControl method with a virtual path to a web user control (*.acsx file) as a parameter to create/load a control or WebUserControl.

  2. Specify the control’s ID property.

  3. Specify the control’s SkinID and EnableTheming properties (optional).

  4. Attach event handlers (if required).

  5. Insert the control into the control hierarchy.

  6. Specify the control’s properties.

  7. Bind the control (for data-aware controls).

csharp
protected void Page_Init(object sender, EventArgs e) {  
    if (Session["Loaded"] != null) {  
        LoadUserControl();  
    }  
}  

protected void ASPxCallbackPanel1_Callback(object source, DevExpress.Web.CallbackEventArgsBase e) {  
    if (e.Parameter == "Show") {  
        LoadUserControl();  
        Session["Loaded"] = true;  
    }  
    else {  
        UnloadUserControl();  
        Session.Remove("Loaded");  
    }  
}  

protected void LoadUserControl() {  
    Control control = LoadControl("~/DataViewUserControl.ascx");  
    control.ID = "uc";  
    ASPxCallbackPanel1.Controls.Add(control);  
}  

protected void UnloadUserControl() {  
    ASPxCallbackPanel1.Controls.Clear();  
}
vb
Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)  
    If Session("Loaded") IsNot Nothing Then  
        LoadUserControl()  
    End If  
End Sub  

Protected Sub ASPxCallbackPanel1_Callback(ByVal source As Object, ByVal e As DevExpress.Web.CallbackEventArgsBase)  
    If e.Parameter = "Show" Then  
        LoadUserControl()  
        Session("Loaded") = True  
    Else  
        UnloadUserControl()  
        Session.Remove("Loaded")  
    End If  
End Sub  

Protected Sub LoadUserControl()  
    Dim control As Control = LoadControl("~/DataViewUserControl.ascx")  
    control.ID = "uc"  
    ASPxCallbackPanel1.Controls.Add(control)  
End Sub  

Protected Sub UnloadUserControl()  
    ASPxCallbackPanel1.Controls.Clear()  
End Sub

See also