[CLOSED] When dynamically creating a TreePanel during page load, how do you hook up the "submitNodes" event?

  1. #1

    [CLOSED] When dynamically creating a TreePanel during page load, how do you hook up the "submitNodes" event?

    I am creating a tree panel dynamically in the page load event of a page, then adding it to some container like a panel. However, I cannot figure out how to handle the "submitNodes" event as I get an error. The final solution will have the ability to add new nodes via drag and drop, but I need a way to be able to know when new nodes have been added. I thought the submitNodes would be a good way to do this - let me know if there is an alternative way to achieve this with the way I have it.

    Here is my ASPX:
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DummyPage.aspx.cs" Inherits="Testing.DummyPage" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <ext:ResourceManager runat="server" ID="resMan" />
        <ext:Panel runat="server" ID="PnlContainer" />
        </div>
        </form>
    </body>
    </html>
    Here is my code behind:
    using System;
    using Ext.Net;
    
    namespace Testing
    {
        public partial class DummyPage : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!X.IsAjaxRequest)
                {
                    var tree = new TreePanel { ID = "testTree" };
                    tree.Title = "Test";
    
                    //and a root node so something is in there
                    var root = new TreeNode { AllowDrag = false, Text = "Form Name", Expanded = true };
                    tree.Root.Add(root);
    
                    //create a save button to perform a "submitNodes"
                    var saveButton = new Button
                    {
                        ID = "saveDef",
                        Icon = Icon.Disk,
                        Text = "Save Changes",
                    };
                    saveButton.Listeners.Click.Handler = "#{testTree}.submitNodes();";
    
                    //add the save button to the buttons of the treepanel
                    tree.ButtonAlign = Alignment.Left;
                    tree.Buttons.Add(saveButton);
    
                    //add the dynamically created treepanel to the container panel
                    PnlContainer.Items.Add(tree);
                }
            }
    
            protected void SubmitNodes(object sender, SubmitEventArgs e)
            {
                X.Msg.Alert("Submit", "You have submitted " + e.RootNode.Children.Count + " nodes").Show();
            }
    
        }
    }
    The error I get is an HTTP 500 server error with:
    System.Web.HttpException: The control with ID 'testTree' not found
    I guess if using
    saveButton.Listeners.Click.Handler = "#{testTree}.submitNodes();";
    is just not going to work because it can't find the control, I need some way of getting the nodes from the client to the server. I have seen some other posts which use a "getJsonTree" javascipt method to get a JSON representation of the tree nodes and send that back to the server, which would work except I can't get a reference to the root node to be able to do that as I have the same problem that I cannot reference the treepanel on the client side when dynamically creating it like this.

    Any help very much appreciated!

    Cheers.
    Last edited by Daniil; Nov 04, 2010 at 10:23 AM. Reason: [CLOSED]
  2. #2
    Hi,

    In the future please post your technical support questions in the Premium Help forum.

    We're always focused on that forum and can miss something in the Help forum. I'm moving this thread to the Premium Help.

    Concerning to the question.

    The ASP.NET is stateless system, i.e. it does NOT recreate controls automatically. It means that you have to recreate controls manually during each request (it's DirectEvent in your case) if would like to handle it on server side.

    Please remove this condition
    if (!X.IsAjaxRequest)
    from your code and it should work fine if there is no other issues.

Similar Threads

  1. Replies: 5
    Last Post: Jul 31, 2012, 2:36 PM
  2. Replies: 5
    Last Post: May 02, 2012, 5:37 PM
  3. Replies: 4
    Last Post: Oct 11, 2011, 2:42 AM
  4. Replies: 2
    Last Post: Jun 26, 2011, 1:59 AM
  5. Replies: 6
    Last Post: Nov 04, 2010, 10:14 AM

Tags for this Thread

Posting Permissions