Oct 13, 2014, 9:35 PM
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
webform.aspx.cs
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! :)
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! :)