在TabContainer中隐藏和显示TabPanel
本文关键字:显示 TabPanel 隐藏 TabContainer | 更新日期: 2023-09-27 18:25:31
当应用程序启动时,我试图隐藏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> <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;
隐藏或显示它,但似乎也不起作用。
ddlToC
未处理SelectedIndexChanged
。
将您的标记更改为:
<asp:DropDownList ID="ddlToC" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlToC_SelectedIndexChanged">