在TabContainer中隐藏和显示TabPanel

时间:2013-07-31 05:33:06

标签: c# asp.net ajaxcontroltoolkit tabpanel

我正在尝试在应用程序启动时隐藏TabPanel4,然后当用户从下拉列表中选择特定项目时,它会为用户显示TabPanel4。下面是我使用的代码,不知道为什么它不起作用。请帮我看一下我的代码,看看我做错了哪一部分。谢谢!

.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>

背后的代码

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

要添加:即使我从aspx页面中删除了Visible="false"并将其设置在Page_Load下的代码后面它不起作用,但当我选择下拉列表中的项目。还尝试使用TabContainer1.Tabs[3].Visible = false / true;来隐藏或显示它,但它似乎也不起作用。

1 个答案:

答案 0 :(得分:0)

ddlToC未处理SelectedIndexChanged

将您的标记更改为:

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