[CLOSED] recreating treestore in code behind

  1. #1

    [CLOSED] recreating treestore in code behind

    Hi

    I have got some trouble recreating a treestore in code behind. I have no problems recreating and repopulating a store of a combobox but somewho the treestore gives me a headache.

    this is how I create it in the first place from code behind:
    TreeStore tStore = new TreeStore();
    tStore.ID = "TS";
    tStore.ReadData += NodeLoad_ReadData;
    tStore.Proxy.Add(new PageProxy { });
    tp.Store.Add(tStore);
    What exactly do I have to recreate to update my store with data on the DirectEvent NodeLoad_ReadData?

    Thank you for every tip.
    Last edited by Daniil; Jul 04, 2014 at 4:28 AM. Reason: [CLOSED]
  2. #2
    Hi @tMp,

    If you do that on each request, then it should work well.

    Please provide a full test case.
  3. #3
    sorry about the delay....

    here you go:
    <%@ Page Language="C#" %>
     
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <script runat="server">
    
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                createTreePanel();            
            }
        }
    
        protected void createTreePanel()
        {
            TreePanel tp = new TreePanel();
            tp.Title = "TreePanel";
            tp.ID = "TP";
            tp.Height = 350;
            tp.BodyPaddingSummary = "10 10 5 10";
            
            // store
            TreeStore tStore = new TreeStore();
            tStore.ID = "TS_STORE";
            tStore.ReadData += NodeLoad_ReadData;
            tStore.Proxy.Add(new PageProxy { });
            tp.Store.Add(tStore);
    
            // root
            tp.Root.Add(new Node { NodeID = "0", Text = "Node 0" });
    
            tp.AddTo(this.Panel);
        }
    
        protected void NodeLoad_ReadData(object sender, NodeLoadEventArgs e)
        {
            // recreate store
            TreeStore store = X.GetCmp<TreeStore>("TP_STORE");
            store.ReadData += NodeLoad_ReadData;
            store.ID = "TS_STORE";
            store.Proxy.Add(new PageProxy { });
    
            string parentNode = e.NodeID;
            for (int i = 0; i < 10; i++)
            {
                Node asyncNode = new Node();
                asyncNode.Text = parentNode + i.ToString();
                asyncNode.NodeID = parentNode + i.ToString();
                e.Nodes.Add(asyncNode);
            }
        }
     
    </script>
     
    <!DOCTYPE html>
     
    <html>
    <head id="Head" runat="server">
        <title></title>
     
    </head>
    <body>
        <form id="Form" runat="server">
            <ext:ResourceManager ID="ResourceManager" runat="server" Locale="de-CH" />
    
                <ext:Panel runat="server" ID="Panel">
                    <Items>
    
                    </Items>
                </ext:Panel>
            
        </form>
    </body>
    </html>
    I am doing something similar with all my other stores and they work. Just the store of the treepanel gives me an error.

    Thank you!
  4. #4
    Thank you for the test case.

    A TreeStore's ReadData event is a DirectEvent. As any DirectEvent it requires a control instance of server. Then the ReadData event occurs the TreeStore is not on the server, because of:
    if (!X.IsAjaxRequest)
    By the way, please replace
    tp.AddTo(this.Panel);
    with
    this.Panel.Items.Add(tp);
    The AddTo method is supposed to be used during an Ext.NET AJAX request only (DirectEvent or DirectMethod).


    I am doing something similar with all my other stores and they work. Just the store of the treepanel gives me an error.
    I think that with such the configuration a regular Store will not work as well.
  5. #5
    ah, yeah. Totally forgot about that. So I have to do it another way, I don't really want to create this store on every reload of the page because it gets not often used... Can I convert this readData somehow in a direct method? Because I want to generate this treepanel on the fly in code behind just when it really is used and then update it, when someone clicks the plus sign.

    about the addTo - no worries, in the original app I am using it corretly from a directevent or -method. It jus slipped in in this stripped down demo version.
  6. #6
    Please review the TreePanel/Loaders examples. I thinks there are options for you.
    https://examples2.ext.net
  7. #7
    Found the loader section....

    Thank you!

Similar Threads

  1. [CLOSED] Recreating Dynamic Controls within a IDynamicUserControl
    By chulcy in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Jun 16, 2014, 7:29 PM
  2. [CLOSED] TreeStore with IHierarchicalDataSource
    By bbros in forum 2.x Legacy Premium Help
    Replies: 8
    Last Post: Oct 26, 2013, 9:25 AM
  3. [CLOSED] Recreating store in code behind
    By tMp in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Aug 30, 2013, 11:30 AM
  4. Replies: 7
    Last Post: Mar 24, 2009, 7:48 AM
  5. [CLOSED] How to recreating controls
    By Jurke in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Oct 28, 2008, 10:50 AM

Tags for this Thread

Posting Permissions