简体   繁体   English

在TabContainer中隐藏和显示TabPanel

[英]Hide and Display of TabPanel in TabContainer

I'm trying to hide the TabPanel4 when the application start, then when user select specific item from the dropdownlist it then display the TabPanel4 out for the user. 我试图在应用程序启动时隐藏TabPanel4 ,然后当用户从下拉列表中选择特定项目时,它会为用户显示TabPanel4 Below is the code I used, not sure why it not working. 下面是我使用的代码,不确定为什么不起作用。 Do help me take a look at my code see which part did I do wrongly. 帮我看看我的代码,看看我做错了什么部分。 Thanks! 谢谢!

Aspx Aspx

<asp:TabContainer ID="TabContainer1" runat="server" Height="75%" Width="100%" UseHorizontalStripPlacement="true"
    ActiveTabIndex="0" OnDemand="true" AutoPostBack="true" TabStripPlacement="Top" ScrollBars="Auto">
<asp:TabPanel ID="TabPanel1" runat="server" HeaderText="Incident Information" Enabled="true" ScrollBars="Auto" OnDemandMode="Once">
<ContentTemplate>
    <table width="100%">
    <tr>
        <td>
            <b>Type of crime:</b>
            <asp:DropDownList ID="ddlToC" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlToC_SelectedIndexChanged">
                <asp:ListItem>Accident</asp:ListItem>
                <asp:ListItem>Theft</asp:ListItem>
                <asp:ListItem>Robbery</asp:ListItem>
                <asp:ListItem>Housebreaking</asp:ListItem>
                <asp:ListItem>Fraud</asp:ListItem>
                <asp:ListItem>Loan Shark</asp:ListItem>
            </asp:DropDownList>
            <br />
        </td>
    </tr>
    </table>
</ContentTemplate>
    </asp:TabPanel>

<asp:TabPanel ID="TabPanel4" runat="server" HeaderText="Property" Enabled="true" ScrollBars="Auto" OnDemandMode="Once" Visible="false">
        <ContentTemplate>
            Is there any property lost in the incident?
            <asp:RadioButton ID="rbPropertyYes" runat="server" GroupName="rbGroup3" Text="Yes" AutoPostBack="True" />
            <asp:RadioButton ID="rbPropertyNo" runat="server" GroupName="rbGroup3" Text="No" AutoPostBack="True" />
            <br />
            <br />
            <asp:Label ID="Label4" runat="server" Text="Describe what was lost in the incident." Visible="False"></asp:Label>
            <br />
            <br />
            <asp:TextBox ID="txtProperty" runat="server" Height="75px" TextWrapping="Wrap" TextMode="MultiLine" Width="400px" Visible="False"/>
            <br />
            <br />
            <asp:Label ID="Label5" runat="server" Text="You have " Visible="False"></asp:Label><asp:Label ID="lblCount3" runat="server" Text="500" Visible="False"></asp:Label>&nbsp;<asp:Label ID="Label6" runat="server" Text=" characters left." Visible="False"></asp:Label>
        </ContentTemplate>
</asp:TabPanel>
</asp:TabContainer>

Code behind 后面的代码

protected void ddlToC_SelectedIndexChanged(object sender, EventArgs e)
{
    if (ddlToC.SelectedValue.Equals("Theft"))
    {
        TabPanel4.Visible = true;
    }
    else if (ddlToC.SelectedValue.Equals("Robbery"))
    {
        TabPanel4.Visible = true;
    }
    else if (ddlToC.SelectedValue.Equals("Housebreaking"))
    {
        TabPanel4.Visible = true;
    }
    else if (ddlToC.SelectedValue.Equals("Fraud"))
    {
        TabPanel4.Visible = true;
    }
}

To add on: even I take away the Visible="false" from the aspx page and set it in code behind page under Page_Load it don't work, it still don't appear when I select the item in the dropdownlist. 补充说明:即使我从aspx页面上删除了Visible="false"并将其设置在Page_Load下的页面后面的代码中,它也不起作用,当我在下拉列表中选择该项时,它仍然不会出现。 Also tried using TabContainer1.Tabs[3].Visible = false / true; 还尝试使用TabContainer1.Tabs[3].Visible = false / true; to hide or display it but it also don't seem to work. 隐藏或显示它,但它似乎也不起作用。

ddlToC is not handling SelectedIndexChanged . ddlToC不处理SelectedIndexChanged

Change your markup to this: 将您的标记更改为此:

<asp:DropDownList ID="ddlToC" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlToC_SelectedIndexChanged">

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

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