[CLOSED] Access dynamic-created TabPanel items

  1. #1

    [CLOSED] Access dynamic-created TabPanel items


    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
    , it returns zero.

     //C# code
                foreach(Ext.Net.Panel Panel in uiTabPanel.Items)
                        if (uiType.SelectedItem.Value == "1")
    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 3:48 AM. Reason: [CLOSED]
  2. #2

    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>
    <head runat="server">
        <title>Ext.NET Examples</title>
        <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 }
        <ext:TabPanel runat="server" ID="TabPanel1">
                <ext:Button runat="server" Flat="true" Icon="Add">
                        <Click OnEvent="AddTab">
                                <ext:Parameter Name="TabsCount" Value="App.TabPanel1.items.length" Mode="Raw" />
                <ext:ToolbarFill runat="server" />
                <ext:Button runat="server" Text="Set 'New Value'">
                        <Click OnEvent="ButtonClick">
                                <ext:Parameter Name="TabsCount" Value="App.TabPanel1.items.length" Mode="Raw" />
  3. #3

    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 3:21 AM.

Similar Threads

  1. Replies: 1
    Last Post: Apr 25, 2013, 6:02 AM
  2. Replies: 12
    Last Post: Jul 26, 2011, 9:43 AM
  3. [CLOSED] Unable to access dynamically created controls
    By rnachman in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 07, 2011, 5:49 AM
  4. [CLOSED] [1.0] Tabstrip with dynamicly created items - items.count always 0
    By klaus.schwarz in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Jul 07, 2010, 11:40 AM
  5. Access to objects created in codebehind
    By Tror in forum 1.x Help
    Replies: 1
    Last Post: Jun 22, 2010, 4:30 AM

Tags for this Thread

Posting Permissions