views:

19

answers:

1

Hello!

I'm wondering if someone can help me with this. I have three TabPanels depending on which tab is clicked I would like to call a different c# function to display different content. I know I could just run all the functions when the page loads but this seems messy. I'm sure there is a way to do this but I'm not having much look. It's possible I'm thinking about this from totally the wrong angle so please let me know if you can think of a better way to do this.

Any help would be greatly appreciated!

Example ASP.net

<ajaxToolkit:TabContainer ID="tabParameters" AutoPostBack="true" Width="100%" runat="server" ActiveTabIndex="0">
<ajaxToolkit:TabPanel ID="tabDetails" OnClientClick="Load_Details()" HeaderText="Details" runat="server">
+1  A: 

I would nest the "functions" into WebUserControls and put them into separate TabPanels. They do nothing on Page.Load and are Invisible. Define a function "BindData" that do all the DataBinding/Time consuming - stuff. When the user changes the ActiveTab (or for the default-active-tab) make that UserControl visible and call its BindData function.

You need UpdatePanels(Updatemode=Conditional) around the UserControl and an Async-Postback-Trigger with Eventname=ActiveTabChanged so that only this Panel is reloaded.

For example on ASPX(MD_Location is the UserControl, for lack of space i only posted one but you must imagine a lot of them):

<act:TabContainer ID="TabContainer1" runat="server" AutoPostBack="true" >
    <act:TabPanel ID="TabLocation" runat="server"  HeaderText="Locations">
        <ContentTemplate>
             <asp:UpdatePanel ID="UpdLocation" runat="server" UpdateMode="Conditional">
                 <ContentTemplate>
                    <MD:MD_Location id="MD_Location" runat="server" Visible="false" />
                 </ContentTemplate>
                 <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="TabContainer1" EventName="ActiveTabChanged" />
                 </Triggers>
             </asp:UpdatePanel>
        </ContentTemplate>
       </act:TabPanel>

and in the Codebehind (sorry, only VB.Net available, i hope you get the idea):

Private Sub TabContainer1_ActiveTabChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabContainer1.ActiveTabChanged
        If Me.TabContainer1.ActiveTab Is Me.TabLocation Then
            Me.MasterDataType = "Locations"
        End If
        switchControlVisibility()
    End Sub

    Private Sub switchControlVisibility()
        Select Case Me.MasterDataType.ToLower
            Case "locations"
                Me.MD_Location.Visible = True
                Me.Lblheader2.Text = "Locations"
                UpdHeader.Update()
                Me.MD_Location.BindData() '<---- do  time-consuming  stuff
                Me.UpdLocation.Update()   

    End Sub

Example

Tim Schmelter