2

I have a tabcontainer with two tabs. The first tab contains a textbox, while the second tab contains a panel.

I want the second tab to be disabled at first page load, and I want it to become enabled as soon as the user enters an input in the textbox in tab1. When textbox in tab1 is emptied again, the second tab should again be disabled.

I tried the following code, but the second tab remains disabled no matter what. Any help would be appreciated. Thank you!

aspx

<asp:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="4" HeaderText=""
    Height="578px" Width="900px" TabStripPlacement="Top" ScrollBars="None" UseVerticalStripPlacement="false"
    VerticalStripWidth="120px" BackColor="White" BorderColor="White" Style="margin-right: 84px">
    <asp:TabPanel ID="TabPanel1" runat="server">
        <HeaderTemplate>
            General
        </HeaderTemplate>
        <ContentTemplate>
             <asp:UpdatePanel ID="TestUpdatePanel" runat="server">
                <ContentTemplate>
                        <table style="height: 247px; width: 100%;">
                            <tr>
                                  <td>
                                       <asp:TextBox ID="HorizonTextBox" runat="server" OnTextChanged="HorizonTextBox_TextChanged"
                                                    AutoPostBack="True"></asp:TextBox>
                                  </td>
                            </tr>
                         </table>
                </ContentTemplate>
             </asp:UpdatePanel>
        <ContentTemplate>
     </asp:TabPanel>
     <asp:TabPanel ID="TabPanel2" runat="server">
         <HeaderTemplate>
            Dashboard
        </HeaderTemplate>
        <ContentTemplate>
            <asp:Button ID="RunSimulationButton" runat="server" Text="Run Simulation" OnClick="RunSimulationButton_OnClick" />
            <br />
            <br />
            <asp:Panel ID="PlotPanel" runat="server">
            </asp:Panel>
        </ContentTemplate>
    </asp:TabPanel>

aspx.cs

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            TabContainer1.ActiveTabIndex = 0;

            TabPanel2.Enabled = false;

        }
    }

    protected void HorizonTextBox_TextChanged(object sender, EventArgs e)
    {
        if(HorizonTextBox.Text != "")
        {
              TabPanel2.Enabled = true;
        }
    }
Mayou
  • 8,498
  • 16
  • 59
  • 98
  • you may need to enclose whole tab container into updatepanel to allow update panel enable/disable child controls – rt2800 Feb 26 '14 at 14:55
  • I tried that, and it still didn't work... Unless I didn't do it properly. Could you please give me a code snapshot of your suggestion? Thank you! – Mayou Feb 26 '14 at 14:59
  • 1
    Sorry I take my previous comment back! It works!! Thank you so much! – Mayou Feb 26 '14 at 15:08
  • Hi, Mariam. Just so you know, you can post your solution as an answer to your own question, if you think it might be helpful to someone in the future. Or, you can just delete the question (using the "delete" link). – Josh Darnell Feb 26 '14 at 15:35
  • I didn't provide the answer, @rt2800 did! I would be happy to accept his answer if he copies his comment and posts it as an answer! – Mayou Feb 26 '14 at 15:53

1 Answers1

0

you may need to enclose whole tab container into updatepanel to allow update panel enable/disable child controls

rt2800
  • 3,045
  • 2
  • 19
  • 26