in
Forums
Blogs
DevExpress.com
Client Center
Support Center
DevExpress Channel

Create CallbackPanel dynamicly

Last post 2/18/2008 2:40 AM by Roman R (Developer Express). 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 2/14/2008 5:21 PM

    Create CallbackPanel dynamicly

    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? 


  • 2/15/2008 6:54 AM In reply to

    Re: Create CallbackPanel dynamicly

    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
    Developer Express Inc.

    PS. If you wish to receive direct assistance from our Support Team, use Support Center.
  • 2/16/2008 5:21 AM In reply to

    Re: Create CallbackPanel dynamicly

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

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

  • 2/18/2008 2:40 AM In reply to

    Re: Create CallbackPanel dynamicly

    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
    Developer Express Inc.

    PS. If you wish to receive direct assistance from our Support Team, use Support Center.
Page 1 of 1 (4 items)
Copyright © 1998-2009 Developer Express Inc.
ALL RIGHTS RESERVED