Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have an api that dynamically adds tabs in a web page. i want to have a drop down so that when user select a item from drop down and click on button so a chart must be created in that newly created tab.
dynamically adding a tab code is given below just please tell me how to add dynamically chart in each tab.

public partial class Default2 : System.Web.UI.Page
{
int tabcount;
private List<string> dynamicTabIDs;

protected void Page_Init(object sender, EventArgs e){
//Checking to see if the dynamicTabIDs are in Session
if (Session["dynamicTabIDs"] != null)
{
//if dynamicTabIDs are in session, recreating the Tabs
//that are associated with the Tab IDs
//and adding them to the TabContainer that will contain
//all of the dynamic tabs.

//retrieving the tab IDs from session:
dynamicTabIDs = (List<string>)Session["dynamicTabIDs"];

//looping through each TabID in session
//and recreating the TabPanel that is associated with that tabID
foreach (string tabID in dynamicTabIDs)
{
//creating a new TabPanel that is associated with the TabID
AjaxControlToolkit.TabPanel tab = new AjaxControlToolkit.TabPanel();
//Setting the ID property of the TabPanel
tab.ID = tabID;
//setting the TabPanel's HeaderText
tab.HeaderText = "Tab " + (TabContainerContent.Tabs.Count + TextBox1.Text).ToString();

//creating a Label to add to the TabPanel...at this point you'll have to
//create whatever controls are required for the tab...
Label tabContent = new Label();
//Giving the Label an ID
tabContent.ID = "lbl_tab_" + TabContainerContent.Tabs.Count.ToString();
//Setting the Label's text
tabContent.Text = "Tab " + (TabContainerContent.Tabs.Count + TextBox1.Text).ToString();

//Adding the Label to the TabPanel
tab.Controls.Add(tabContent);

//Adding the TabPanel to the TabContainer that contains the dynamic tabs
TabContainerContent.Tabs.Add(tab);
}
}
else
{ //Creating a new list of dynamicTabIDs because one doesn't exist yet in session.
dynamicTabIDs = new List<string>();
}
}

protected void Page_PreRender(object sender, EventArgs e){
Session["dynamicTabIDs"] = dynamicTabIDs;
}
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
//creating a new TabPanel t
AjaxControlToolkit.TabPanel tab = new AjaxControlToolkit.TabPanel();
//Setting the ID property of the TabPanel
tab.ID = "tab" + Convert.ToString(TabContainerContent.Tabs.Count);
//setting the TabPanel's HeaderText
tab.HeaderText = "Tab " + (TabContainerContent.Tabs.Count + TextBox1.Text).ToString();

//creating a Label to add to the TabPanel...at this point you'll have to
//create whatever controls are required for the tab...
Label tabContent = new Label();
//Giving the Label an ID
tabContent.ID = "lbl_tab_" + TabContainerContent.Tabs.Count.ToString();
//Setting the Label's text
tabContent.Text = "Tab " + (TabContainerContent.Tabs.Count + TextBox1.Text).ToString();

//Adding the Label to the TabPanel
tab.Controls.Add(tabContent);

//Adding the TabPanel to the TabContainer that contains the dynamic tabs
TabContainerContent.Tabs.Add(tab);

//Setting the ActiveTab to the newest tab added
//Please be aware that you MUST set the ActiveTab or else you'll run into an exception
TabContainerContent.ActiveTab = tab;

//Adding the Tab's ID to the dynamicTabIDs list
dynamicTabIDs.Add(tab.ID);
}

protected void TabContainerContent_OnActiveTabChanged(object sender, EventArgs e) {
//displaying the ID of the active tab
currentTabIndex.Text=TabContainerContent.ActiveTab.ID;
}
}
Posted
Comments
Sergey Alexandrovich Kryukov 1-Aug-11 0:30am    
Not a question. Why Ajax; where is Ajax code? Why not doing chart on server side in .NET, which is well-known thing?
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900