0

i am working on a project.but i have a problem.basically,i am using ajaxtoolkit tabcontainer.assume that i have 2 tabs which i created.let's call them tab1,tab2.in tab1 there is a button and textbox.when i click the button,i am writing some text into the textbox.then i am creating a tab dynamically.assume that it is called "tab3".the problem is when i click the button in the tab1,tab3 is diappearing.how can i prevent this?

   <asp:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0"  AutoPostBack="true"
        Height="273px" Width="1050px">
        <asp:TabPanel runat="server" HeaderText="tab1" ID="tab1">       
    <ContentTemplate>


tab2

here is where i am adding a new tab in the function:

       AjaxControlToolkit.TabPanel tp = new AjaxControlToolkit.TabPanel();
        tp.HeaderText = "tab3";
        tp.ContentTemplate = Page.LoadTemplate("WebUserControl1.ascx");
        tp.ID = "tab3";
        TabContainer1.Tabs.Add(tp);

The html part is: part:blahblahblahblah

Sam Saffron
  • 128,308
  • 78
  • 326
  • 506
Ktl
  • 1
  • 2

1 Answers1

1

When dealing with any dynamic controls, you will need to re-add them after every postback. My recommendation is to store your dynamically-added controls in the ViewState, and write a method that retrieves the information from ViewState and adds your tabs. Then call this method from Page_Init.

Keith
  • 5,311
  • 3
  • 34
  • 50
  • well i was trying to do that.when i clicked a button i created a new tab.and i added it into viewstate.but in page_load method,i cant retrieve it.here is the code: – Ktl Dec 30 '10 at 18:46
  • AjaxControlToolkit.TabPanel tp = new AjaxControlToolkit.TabPanel(); tp.HeaderText = "Tab1"; tp.ContentTemplate = Page.LoadTemplate("WebUserControl1.ascx"); tp.ID = "tab1"; ViewState["tab1"] =tp; TabContainer1.Tabs.Add(tp); //Page.RegisterStartupScript("myScript", javaScript); TabContainer1.ActiveTab = TabContainer1.Tabs[4]; TabContainer1.ActiveTab.Visible = true; – Ktl Dec 30 '10 at 18:46
  • protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { AjaxControlToolkit.TabPanel tp = new AjaxControlToolkit.TabPanel(); tp = (AjaxControlToolkit.TabPanel)ViewState["tab1"]; TabContainer1.Tabs.Add(tp); } } – Ktl Dec 30 '10 at 18:48