Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi every one

Requirement I want to create Tabpanels dynamically i used Below Code to achive it

VB
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim Temptab As AjaxControlToolkit.TabPanel

    Dim i As Integer = 0

    Dim lbl As Label
    For i = 1 To 5
        lbl = New Label
        lbl.Text = "Hi i m Tab no : " & i + 1

        Temptab = New AjaxControlToolkit.TabPanel()
        Temptab.ID = "NewTab" & TabContainer1.Tabs.Count + 1
        Temptab.HeaderText = "New Tab " & TabContainer1.Tabs.Count + 1
        Temptab.Controls.Add(lbl)

        TabContainer1.Tabs.Add(Temptab)


End Sub


this Button1 is inside the Update panel and Tab container too

Problem When ever i click Button one , this code adds only one tabpanel, on second click previously created Tabpanel goes off,

i want something like Multiple pages [aspx forms] should be opened in multiple tabs[Not Browser Tabs my tab controller tab],

I know Dude to post back these controls are losing but i cant create all dynamically created Controls after every postback cause i will get huge amount of controls to create and Time Consuming.

Do we have any alternative Solution or some other control or anything to achieve my functionality

Thanks In Advance.
Posted

1 solution

This line is your problem.

C#
Temptab = New AjaxControlToolkit.TabPanel()


You reinitialise the control with each click of the button. This clears the tabs.

The tab control should be constructed and included within the main page load.

So add the tab control and initialise it during the page load event.

You can manage if it's rendered using the Visibility property.

This will register the control properly within the ASP.Net event architecture.

Then when the page posts back and reloads. ASP.Net engine can use the ViewState to manage and reconstruct the previous state of the control.

Leaving you only needing to make it visible and add the tab in your button event.
 
Share this answer
 

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