PDA

View Full Version : [CLOSED] Dynamically adding controls to a tav



riccardosarti
Sep 24, 2008, 9:37 AM
I tried to build a TabPanel dynamically: adding Tabs to TabPanel and Buttons to each tabs. In the follow I list a very simple example. Issues come as Buttons doesn't show up properly. They come on top of the TabPanel instead of being shown inside of each appropiate Tab.
In the example each Tab is added with a Panel which is suposed to hold the Buttons. I also tried to add Button to either the Tab.Items or Tab.Control collection directly but nothing happens

can anyone help please?






protected void Page_Load(object sender, EventArgs e)
{
Coolite.Ext.Web.TabPanel tabs = new Coolite.Ext.Web.TabPanel();
tabs.ResizeTabs = true;
tabs.MinTabWidth = Unit.Pixel(115);
tabs.TabWidth = Unit.Pixel(135);
tabs.EnableTabScroll = true;
tabs.Width = Unit.Pixel(600);
tabs.Height = Unit.Pixel(300);
tabs.ActiveTab = 0;
tabs.BodyBorder = false;
tabs.Border = true;
for (int i = 1; i<4; i++)
{
Tab tab = new Tab();
tab.Title = "world " + i.ToString();
tab.IconCls = "tabs";
tab.Closable = false;
tab.BodyStyle = "padding: 6px;";
tab.Frame = false;
Coolite.Ext.Web.Panel p = new Coolite.Ext.Web.Panel();
for (int j = 0; j < i; j++)
{
Coolite.Ext.Web.Button btn = new Coolite.Ext.Web.Button();
btn.Text = "type " + i.ToString() + "_" + j.ToString();
btn.ToolTip = "description for type " + i.ToString() + "_" + j.ToString();
btn.Visible = true;
p.Controls.Add(btn);
}
tab.Items.Add(p);
tabs.Tabs.Add(tab);
}
this.PlaceHolder1.Controls.Add(tabs);
}

geoffrey.mcgill
Sep 24, 2008, 9:43 AM
I took a quick look at your code sample and I think you just need to add the Button(s) to the Panel's .ContentControls collection instead of the .Controls collection.

Example


// Old
p.Controls.Add(btn);


// New
p.ContentControls.Add(btn);
Hope this helps. Let us know if this solves the problem.

geoffrey.mcgill
Sep 24, 2008, 9:45 AM
I think the Panel needs to be added to Tab's .ContentControls collection as well.

Example


tab.ContentControls.Add(p);

riccardosarti
Sep 24, 2008, 9:49 AM
OK thx all, also found this topic had already been discussed. Sorry for the post