[CLOSED] Add tab from TreePanel builded in code behind

  1. #1

    [CLOSED] Add tab from TreePanel builded in code behind

    Last edited by Daniil; Jul 23, 2012 at 2:31 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Welcome to Ext.NET!

    There are several issues.

    1. The default Namespace is "App". So, you should use
    App.TabPanel1
    or
    #{TabPanel1}
    2. I don't think you should use Href, because it creates an anchor tag with that href. So, the link will be opened when a user clicks a node. I would use an additional field, for example, "url".

    3. You should worry about the tabs ids. With all your ItemClick variations there will be just "idopc" for any node. I would use an additional field as well. Though in my example I used just "text" for simplifying.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            this.TreePanel1.Listeners.ItemClick.Handler = "addTab(App.TabPanel1, record);";
        }
    </script>
    
    <!DOCTYPE />
    
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    
        <script type="text/javascript">
            var addTab = function (tabPanel, record) {
                var text = record.data.text,
                    tab = tabPanel.getComponent(text);
    
                if (!tab) {
                    tab = tabPanel.add({
                        id       : text,
                        title    : text,
                        closable : true,
                        loader   : {
                            url      : record.data.url,
                            renderer : "frame",
                            loadMask : {
                                showMask : true,
                                msg      : "Loading " + text + "..."
                            }
                        }
                    });
                }
                tabPanel.setActiveTab(tab);
            };
        </script>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
        <ext:TreePanel 
            ID="TreePanel1" 
            runat="server" 
            Height="50" 
            RootVisible="false">
            <Fields>
                <ext:ModelField Name="url" />
            </Fields>
            <Root>
                <ext:Node Expanded="true">
                    <Children>
                        <ext:Node Text="Ext.NET" Leaf="true" Href="sgdfs">
                            <CustomAttributes>
                                <ext:ConfigItem Name="url" Value="http://ext.net" Mode="Value" />
                            </CustomAttributes>
                        </ext:Node>
                        <ext:Node Text="Ext.NET forums" Leaf="true">
                            <CustomAttributes>
                                <ext:ConfigItem Name="url" Value="http://forums.ext.net" Mode="Value" />
                            </CustomAttributes>
                        </ext:Node>
                    </Children>
                </ext:Node>
            </Root>
        </ext:TreePanel>
        <ext:TabPanel ID="TabPanel1" runat="server" />
    </body>
    </html>
  3. #3
  4. #4
    I guess you have missed that section:
    <Fields>
        <ext:ModelField Name="url" />
    </Fields>
    of the TreePanel in my example.
  5. #5

    Solved!

    Yes i did, it's working perfectly now.

    Thank you Daniil.

Similar Threads

  1. Replies: 14
    Last Post: May 16, 2012, 7:26 AM
  2. Replies: 0
    Last Post: Nov 16, 2011, 10:07 AM
  3. Replies: 2
    Last Post: Oct 10, 2011, 1:29 AM
  4. TreePanel from Code
    By snouto in forum 1.x Help
    Replies: 3
    Last Post: Nov 23, 2010, 12:29 PM
  5. Suggesstion with code: GetNodeById for TreePanel
    By reverseblade in forum 1.x Help
    Replies: 3
    Last Post: Aug 20, 2010, 11:12 AM

Tags for this Thread

Posting Permissions