I got 15 tabs and 15 user controls assigned to each tab. All are loading at once which id delaying the process. I want to load one user control on selection of a tab in tab container.
A:
Instead of adding all controls declaratively on the page, add them programmatically on the tab change event. See this link: http://msdn.microsoft.com/en-us/library/c0az2h86.aspx
Or here's the short version..
Change the Register declaration at the top of the page, to a reference:
<%@ Reference Control="MyUserControl.ascx" %>
In your tab change event, load the the uc from file:
Dim uc As MyUserControl = CType(LoadControl("MyUserControl.ascx"), MyUserControl)
Add the control to the page:
PlaceHolder1.Controls.Add(uc)
Antony Highsky
2010-06-14 06:48:44
Please clarify the tab change event.Is it the TabContainerSettings_ActiveTabChanged?There are tab changed events for a particular tab.
Yajuvendra
2010-06-14 11:00:45
Yes, that's assuming you are using AJAX control toolkit.
Antony Highsky
2010-06-14 14:58:46
Thanks.But got one problem.when i click on a tab the controls are showing up and disappearing again.
Yajuvendra
2010-06-15 12:27:52
Sounds like something else, other than selecting a tab, may be causing a second postback. Hard to tell w/o seeing the rest of the code. When the control disappears, are you still left on the same tab or returned to the default one?
Antony Highsky
2010-06-15 18:05:26
A:
Here's the complete solution. The markup...
<%@ Reference Control="~/MyUserControl.ascx" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<asp:TabContainer ID="TabContainer1" runat="server" AutoPostBack="true">
<asp:TabPanel id="Tab1" runat="server">
<HeaderTemplate>
Tab1
</HeaderTemplate>
<ContentTemplate>
Tab 1 static content
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel id="Tab2" runat="server">
<HeaderTemplate>
Tab2
</HeaderTemplate>
<ContentTemplate>
<!-- user control will be loaded here -->
</ContentTemplate>
</asp:TabPanel>
</asp:TabContainer>
...and codebehind:
Protected Sub TabContainer1_ActiveTabChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabContainer1.ActiveTabChanged
If TabContainer1.ActiveTabIndex = 1 Then
Dim uc As MyUserControl = CType(LoadControl("MyUserControl.ascx"), MyUserControl)
Tab2.Controls.Add(uc)
End If
End Sub
Antony Highsky
2010-06-14 15:13:10