Iterate items of tabPanel with tabs added by CodeBehind

  1. #1

    Iterate items of tabPanel with tabs added by CodeBehind

    Hello again,

    This time I am trying to verify if I already have created a tab before re-creating it from code behind, with no luck.

    In my mind, all I should do was itereate thru the tabPanel items to see if any of them had the 'ID=' property I set to it, with no luck.

    A code says more than a thousand words and screenshots, so:


    webform.aspx
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="codeBehindTabs.aspx.cs" Inherits="ExtNetPlayground.codeBehindTabs" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
        <form id="form1" runat="server">
        <div>
            <ext:TabPanel runat="server" ID="tp1">
                <Items>
                    <ext:Panel runat="server" ID="pn0" Closable="false" Title="Panel Base" />
                    <ext:Panel runat="server" ID="pn1" Closable="true" Title="Panel cod 1" />
                </Items>
            </ext:TabPanel>
            <ext:Button runat="server" OnDirectClick="makeTab" Text="Create tab from code behind" />
        </div>
        </form>
    </body>
    </html>


    webform.aspx.cs
    using Ext.Net;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    using x = Ext.Net; // avoids conflicts
    
    namespace ExtNetPlayground
    {
        public partial class codeBehindTabs : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
            }
    
            protected void makeTab(object sender, DirectEventArgs e)
            {
                if (tp1.Items.Find(i => i.ID == "pn2") == null)
                {
                    var newTab = new x.Panel() { ID = "pn2", Title = "Dynamic Tab", Closable = true };
                    newTab.AddTo(tp1);
                }
                else
                {
                    var msgA = new MessageBoxConfig();
                    msgA.Buttons = MessageBox.Button.OK;
                    msgA.Icon = MessageBox.Icon.INFO;
                    msgA.Title = "Tab already exists";
                    msgA.Message = "No-go, tab already exists.";
                    X.Msg.Show(msgA);
                }
            }
        }
    }



    I can find pn0 and pn1 among the items but can't find the created pn2 when I click the button for the second time, thus the 'else' on makeTab() is never triggered. :(

    Thanks for the advices -- in advance! :)
  2. #2
    Hi @avenger,

    You create a control during one request and want to get it during another request. The short answer is no way. A bit longer answer is... ASP.NET doesn't maintain the controls across the requests automatically. If a developer need some control during all the request, he has to recreate that control during each request. For example, in Page_Load.

    Here is a bit more words on that.
    http://forums.ext.net/showthread.php...l=1#post174861

    Personally, I would avoid recreating controls each request. In your specific case, you could mark somehow on the server that the Panel is created. For example, a small bool variable in the Session.
  3. #3
    Thanks Daniil... Too bad its an ASP.NET limitation but then, I guess I will just use the "feature" to always refresh the tab when the customers asks to re-open it, and not treat this as an additional overhead otherwise.

    By the way, the bit on the session is a good idea really, I'll keep that in mind for other situations, thanks for the suggestion! It would be useful e.g to keep the tabs open during the session should the user switch pages back and forth.

Similar Threads

  1. Iterate ComboBox Items
    By Alaswad in forum 2.x Help
    Replies: 1
    Last Post: Sep 17, 2014, 5:27 PM
  2. Replies: 12
    Last Post: Jun 04, 2012, 11:18 AM
  3. Tabs are not added to tabPanel
    By Vaishali in forum 1.x Help
    Replies: 26
    Last Post: Feb 21, 2012, 8:13 AM
  4. Replies: 1
    Last Post: Dec 06, 2010, 8:51 AM
  5. Replies: 4
    Last Post: Jul 01, 2010, 1:49 AM

Tags for this Thread

Posting Permissions