saifullah khan

saifullah khan

  • NA
  • 335
  • 301k

Add chart programatically in ajax controls

Jul 30 2011 3:08 AM
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;
    }
}

Answers (1)