简体   繁体   中英

Enable tabpanel in tabcontainer

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;
        }
    }

您可能需要将整个选项卡容器包含在updatepanel中,以允许更新面板启用/禁用子控件

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM