简体   繁体   English

在tabcontainer中启用tabpanel

[英]Enable tabpanel in tabcontainer

I have a tabcontainer with two tabs. 我有一个带有两个标签的tabcontainer。 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. 我希望在第一页加载时禁用第二个选项卡,并且我希望用户在tab1的文本框中输入一个输入后立即启用它。 When textbox in tab1 is emptied again, the second tab should again be disabled. 当再次清空tab1中的文本框时,应再次禁用第二个选项卡。

I tried the following code, but the second tab remains disabled no matter what. 我尝试了以下代码,但是无论如何,第二个选项卡仍然处于禁用状态。 Any help would be appreciated. 任何帮助,将不胜感激。 Thank you! 谢谢!

aspx 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 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中,以允许更新面板启用/禁用子控件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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