locked
Where do I load the content (data) for controls in a TabPanel? RRS feed

  • Question

  • User1453632690 posted

    In all of my hours of searching, I have yet to find any code examples that show the code-behind for a page containing a TabContainer and TabPanel. I would like to see the best way(s) to load data and set values for controls in a TabPanel. Can anyone provide me with some examples or links?

    Thanks

    Wednesday, November 25, 2015 2:13 PM

Answers

  • User61956409 posted

    Hi jnickFL1,

    I would like to see the best way(s) to load data and set values for controls in a TabPanel

    You could try to load data and set values for controls in TabContainer ActiveTabChanged event, the following sample is for your reference.

    <asp:TabContainer ID="Tabs" runat="server" ActiveTabIndex="0" Height="128px"
        Width="332px" OnDemand="true" OnActiveTabChanged="Tabs_ActiveTabChanged">
        <asp:TabPanel runat="server" HeaderText="TabPanel1" ID="TabPanel1">
            <ContentTemplate>
                I'm tab 1
                <br />
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            </ContentTemplate>
        </asp:TabPanel>
        <asp:TabPanel ID="TabPanel2" runat="server" HeaderText="TabPanel2">
            <ContentTemplate>
                I'm tab 2<br />
                <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
            </ContentTemplate>
        </asp:TabPanel>
        <asp:TabPanel ID="TabPanel3" runat="server" HeaderText="TabPanel3">
            <ContentTemplate>
                I'm tab 3
            </ContentTemplate>
        </asp:TabPanel>
    </asp:TabContainer>
    
    protected void Tabs_ActiveTabChanged(object sender, EventArgs e)
    {
        if (Tabs.ActiveTabIndex==1)
        {
            TextBox2.Text = "hello world";
        }  
    }
    

    Best Regards,

    Fei Han



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 26, 2015 5:23 AM

All replies

  • User603616845 posted

    Hi,

    code examples that show the code-behind for a page containing a TabContainer and TabPanel.

    If you want to add your tab container with tab panel using code behind page in asp.net. following is the code for this..

    TabPanel FirstTab= new TabPanel();  
    FirstTab.ID = "Tab1";  
    FirstTab.HeaderText = "First Tab";  
    
    TabPanel SecondTab = new TabPanel();  
    SecondTab.ID = "Tab2";  
    SecondTab.HeaderText = "Second Tab";  
    
    TabContainer1.Tabs.Add(FirstTab);  //add it to the Tab Container control 
    TabContainer1.Tabs.Add(SecondTab);  
    
    //to added content on it you can do like this 
    Image _image = new Image();
    _image.ID = "image";
    _image.ImageUrl = "~/images/test.gif";
    FirstTab.Controls.Add(image);
    
    TabContainer1.ActiveTabIndex = 0;  // set your active tab index to display. 

    You can also learn how to add tab container with tab panel step by step with lots of article over internet.

    Hope this will help you.

    thanks

    Thursday, November 26, 2015 5:03 AM
  • User61956409 posted

    Hi jnickFL1,

    I would like to see the best way(s) to load data and set values for controls in a TabPanel

    You could try to load data and set values for controls in TabContainer ActiveTabChanged event, the following sample is for your reference.

    <asp:TabContainer ID="Tabs" runat="server" ActiveTabIndex="0" Height="128px"
        Width="332px" OnDemand="true" OnActiveTabChanged="Tabs_ActiveTabChanged">
        <asp:TabPanel runat="server" HeaderText="TabPanel1" ID="TabPanel1">
            <ContentTemplate>
                I'm tab 1
                <br />
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            </ContentTemplate>
        </asp:TabPanel>
        <asp:TabPanel ID="TabPanel2" runat="server" HeaderText="TabPanel2">
            <ContentTemplate>
                I'm tab 2<br />
                <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
            </ContentTemplate>
        </asp:TabPanel>
        <asp:TabPanel ID="TabPanel3" runat="server" HeaderText="TabPanel3">
            <ContentTemplate>
                I'm tab 3
            </ContentTemplate>
        </asp:TabPanel>
    </asp:TabContainer>
    
    protected void Tabs_ActiveTabChanged(object sender, EventArgs e)
    {
        if (Tabs.ActiveTabIndex==1)
        {
            TextBox2.Text = "hello world";
        }  
    }
    

    Best Regards,

    Fei Han



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 26, 2015 5:23 AM