Forums

Create CallbackPanel dynamicly

Last post 2/18/2008 2:40 AM by Roma R (DevExpress). 3 replies.
Sort Posts: Previous Next
  • Mattias Johansson

    Create CallbackPanel dynamicly

    2/14/2008 5:21 PM
    • Not Ranked
    • Joined on 1/17/2008
    • Posts 29

    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? 


  • Roma R (DevExpress)

    Re: Create CallbackPanel dynamicly

    2/15/2008 6:54 AM
    • Top 50 Contributor
    • Joined on 5/4/2007
    • Posts 486
    Answer

    Hi Mattias

    In ASP.NET a control hierarchy isn't preserved in the viewstate. You should create it every time(on each page load).
    So, you should remove the following condition from your code:

       if (!IsPostBack)

    Thanks, Roman
    R&D, .Net Team, DevExpress

    PS. If you wish to receive direct assistance from our Support Team, use Support Center.
  • Mattias Johansson

    Re: Create CallbackPanel dynamicly

    2/16/2008 5:21 AM
    • Not Ranked
    • Joined on 1/17/2008
    • Posts 29

    Oh, ok! Yes, it seems to work! :)

    But I thought that a ASPxCallbackPanel isn't making a PostBack!?

  • Roma R (DevExpress)

    Re: Create CallbackPanel dynamicly

    2/18/2008 2:40 AM
    • Top 50 Contributor
    • Joined on 5/4/2007
    • Posts 486
    The ASPxCallbackPanel sends a callback.
    Except for the first page load, the Page's IsPostBack property always returns true, no matter be it a callback or postback.

    Thanks, Roman
    R&D, .Net Team, DevExpress

    PS. If you wish to receive direct assistance from our Support Team, use Support Center.
More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.