[CLOSED] Access dynamic-created TabPanel items

  1. #1

    [CLOSED] Access dynamic-created TabPanel items

    Hi,

    Because of the complexity of the application; I have to generate Ext components dynamically from C#.

    I have a TabPanel and upon user interaction, tabs are added to the panel dynamically from C#. So far, that's working, but the point is to persist the data held in in each tab, but I'm failing to even reach any of the generated panels.

    this is what I'm trying; the code inside the foreach is never reached (even if I have 20 tabs in the tabpanel) and when I do a
    uiTabPanel.Items.Count
    , it returns zero.

     //C# code
                foreach(Ext.Net.Panel Panel in uiTabPanel.Items)
                {                
                        if (uiType.SelectedItem.Value == "1")
                        {
                            SaveTypeB(Panel);
                        }
                        else
                        {
                            SaveTypeA(Panel);
                        }                    
                    }
                }
    I'm trying to access the generated tabs from a DirectMethod called when clicking a 'Save' button.
    Last edited by Daniil; Aug 13, 2013 at 4:48 AM. Reason: [CLOSED]
  2. #2
    Hello!

    Unfortunately, it's the nature of ASP.NET and Web, you cannot access dynamic field because Web is stateless. But you can use ExtraParams or HiddenField to submit some values back to the server. Also, you can use X.GetCmp method:

    <%@ Page Language="C#" %>
    
    <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET Examples</title>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
        
        <script runat="server">
            protected void ButtonClick(object sender, DirectEventArgs e)
            {
                int tabsCount = int.Parse(e.ExtraParams["TabsCount"]);
    
                for (int i = 0; i < tabsCount; i++)
                {
                    X.GetCmp<TextField>("TextFieldInTab" + i).SetValue("New Value");
                }
            }
            
            protected void AddTab(object sender, DirectEventArgs e)
            {
                string tabsCount = e.ExtraParams["TabsCount"];
                
                Ext.Net.Panel panel = new Ext.Net.Panel
                {
                    Title = "Tab " + tabsCount,
                    Closable = true,
                    Layout = "Fit",
                    Items = { 
                        new TextField { FieldLabel = "My text field " + tabsCount, ID = "TextFieldInTab" + tabsCount }
                    }
                };
                TabPanel1.Add(panel);
                panel.Render();
    
                TabPanel1.SetLastTabAsActive();            
            }
        </script>
       
        <ext:TabPanel runat="server" ID="TabPanel1">
            <TabBar>
                <ext:Button runat="server" Flat="true" Icon="Add">
                    <DirectEvents>
                        <Click OnEvent="AddTab">
                            <ExtraParams>
                                <ext:Parameter Name="TabsCount" Value="App.TabPanel1.items.length" Mode="Raw" />
                            </ExtraParams>
                        </Click>
                    </DirectEvents>
                </ext:Button>
                <ext:ToolbarFill runat="server" />
            </TabBar>
            <Buttons>
                <ext:Button runat="server" Text="Set 'New Value'">
                    <DirectEvents>
                        <Click OnEvent="ButtonClick">
                            <ExtraParams>
                                <ext:Parameter Name="TabsCount" Value="App.TabPanel1.items.length" Mode="Raw" />
                            </ExtraParams>
                        </Click>
                    </DirectEvents>
                </ext:Button>
            </Buttons>
        </ext:TabPanel>    
    </body>
    </html>
  3. #3
    Thanks.

    Any idea why this won't work as expected? I would not only try get the number of items but actually manipulate them programmatically (like in your example you set the value to a textfield).

    //c# code
    int numOfPanels = X.GetCmp<TabPanel>("uiTabPanel").Items.Count; //returns 0
    int numOfPanels2 = ((TabPanel)X.GetCmp("uiTabPanel")).Items.Count; //returns 0
    How come, through X.getCmp, I'd be able to set the value of a dynamically created textfield but not being able to refer to a dynamically created panel and its components?
  4. #4
    X.GetCmp creates an empty instance of specific component and doesn't keep your data between requests, as you remember Web is stateless.

    You can use it as a tool to simplify making some changes. Therefore, it's not possible to get component's Items collection using it, it's always empty.

    What you should do is to use ExtraParams to send count of tabs from the client. Look at the ButtonClick method in the example above.
    Last edited by Baidaly; Aug 07, 2013 at 4:21 AM.

Similar Threads

  1. Replies: 1
    Last Post: Apr 25, 2013, 7:02 AM
  2. Replies: 12
    Last Post: Jul 26, 2011, 10:43 AM
  3. [CLOSED] Unable to access dynamically created controls
    By rnachman in forum 1.x Premium Help
    Replies: 1
    Last Post: Apr 07, 2011, 6:49 AM
  4. Replies: 4
    Last Post: Jul 07, 2010, 12:40 PM
  5. Access to objects created in codebehind
    By Tror in forum 1.x Help
    Replies: 1
    Last Post: Jun 22, 2010, 5:30 AM

Tags for this Thread

Posting Permissions