I cannot get this to work, I'm getting this error:
A server error has occurred while a callBack has
being processed on the server.
when I click the button.
<asp:Panel ID="test" runat="server">
</asp:Panel>
...
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ASPxCallbackPanel Panel = new ASPxCallbackPanel();
Panel.ClientInstanceName = "testpanel";
Panel.Callback += new CallbackEventHandlerBase(ASPxCallbackPanel1_Callback);
ASPxButton BrowseButton = new ASPxButton();
BrowseButton.Text = "ok";
BrowseButton.AutoPostBack = false;
BrowseButton.Native = true;
BrowseButton.EncodeHtml = false;
BrowseButton.ClientSideEvents.Click = "function(s, e) {" + Panel.ClientInstanceName + ".PerformCallback('test');}";
test.Controls.Add(Panel);
test.Controls.Add(BrowseButton);
}
}
protected void ASPxCallbackPanel1_Callback(object source, CallbackEventArgsBase e)
{
ASPxCallbackPanel panel = (ASPxCallbackPanel)source;
Label text = new Label();
text.Text = e.Parameter.ToString();
panel.Controls.Add(text);
}
If I create the panel and the button in the design for testing it works, like this:
<dxcp:ASPxCallbackPanel ID="ASPxCallbackPanel1" ClientInstanceName="Panel1" runat="server" Width="200px" OnCallback="ASPxCallbackPanel1_Callback">
</dxcp:ASPxCallbackPanel>
<dxe:ASPxButton ID="ASPxButton1" runat="server" Text="ASPxButton" AutoPostBack="false" Native="true" ClientSideEvents-Click="function(s, e) {Panel1.PerformCallback('test');}">
</dxe:ASPxButton>
So, why doesn't it works codebehind?