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. 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
<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>
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. Also tried using
TabContainer1.Tabs[3].Visible = false / true;to hide or display it but it also don't seem to work.