I’m creating a registration form on my school project website. I have given a dropdown menu for security questions and if user wants to type his own question he/she can select other and then a textbox will show which I’ve set visible=false by default.
I tried with this code but it is not working is there anything that I’m missing.
protected void selectques_SelectedIndexChanged(object sender, EventArgs e)
{
if (selectques.Text == "Other")
{
alterquestion.Visible = true;
}
}
DropdownList:
<asp:DropDownList ID="selectques" runat="server" Height="25px" Width="254px" OnSelectedIndexChanged="selectques_SelectedIndexChanged">
<asp:ListItem>Select a question?</asp:ListItem>
<asp:ListItem> What is your pet name?</asp:ListItem>
<asp:ListItem>Who is your first teacher?</asp:ListItem>
<asp:ListItem>Which is your favourite movie?</asp:ListItem>
<asp:ListItem>Whom you like most in your life?</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
</asp:DropDownList>
Hidden TextBox:
<asp:TextBox ID="alterquestion" runat="server" Height="20px" Width="250px" Visible="false"></asp:TextBox>
DropDownList.Textproperty gives youSelectedValueof theDropDownList. but as per your list items there is no value fieldyou need to check
selectques.SelectedItem.Textproperty to find your ListItem or you can add value field to your list items.Edit:
set DropDownList AutoPostBack as true