The target 'X' for the callback could not be found or did not implement ICallbackEventHandler
- 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:
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.
Specify the control’s ID property.
All child controls in a naming container have IDs based on the ID of this container. For example, if an instance of the ASPxDataView with the static ID “ASPxDataView1” is a part of a user control (DataViewUserControl.ascx), its result ID is DataViewUserControl_ASPxDataView1. If a control has no static ID, it is generated dynamically on each request.
Specify the control’s SkinID and EnableTheming properties (optional).
Attach event handlers (if required).
Insert the control into the control hierarchy.
You should restore the control with the same settings in the Page_Init event when you modify the control hierarchy.
Specify the control’s properties.
Bind the control (for data-aware controls).
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();
}