setting autopost to true and hiding and showing label and dropdown list based off seperate dropdown llist

Joseph Hedbon 141 Reputation points
2023-10-26T04:28:53.3466667+00:00

this is probably simple and i'm probably missing one thing to get it to work. i have a label and dropdown list with their default properties for visbility set to false. on the webform there is another dropdown list with 2 entries i populated and assigned the values in the property to 0 and 1.

this is the current code i have:

Private Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged

    If DropDownList1.SelectedIndex = 1 Then
        Label6.Visible = True
        DropDownList2.Visible = True
    ElseIf DropDownList1.SelectedIndex = 0 Then
        Label6.Visible = False
        DropDownList2.Visible = False
    End If
End Sub


<asp:DropDownList ID="DropDownList2" runat="server" style="z-index: 1; left: 120px; top: 205px; position: absolute" Font-Bold="True" Visible="False" >
    <asp:ListItem Value="1">4 Year Term</asp:ListItem>
    <asp:ListItem Value="2">10 Year Term</asp:ListItem>
    <asp:ListItem Value="3">15 Year Decreasing</asp:ListItem>
    <asp:ListItem Value="4">20 Year</asp:ListItem>
    <asp:ListItem Value="5">30 Year Decreasing</asp:ListItem>
    <asp:ListItem Value="6">Term to 65</asp:ListItem>
    <asp:ListItem Value="7">Term to 100</asp:ListItem>
</asp:DropDownList>

this is the drop down list that would trigger either showing or hiding dropdownlist2

<asp:DropDownList ID="DropDownList1" runat="server" style="z-index: 1; left: 120px; top: 176px; position: absolute" Font-Bold="True">
    
    <asp:ListItem Value="0">Whole Life</asp:ListItem>
    <asp:ListItem Value="1">Term</asp:ListItem>
</asp:DropDownList>


any help much appreciated, heard something about autopost property not sure how to implement that.

ASP.NET Web Forms
ASP.NET Web Forms
A part of the ASP.NET web application framework that can be used to create ASP.NET web applications.
660 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,410 questions
0 comments No comments
{count} votes

Accepted answer
  1. Lan Huang-MSFT 20,136 Reputation points Microsoft Vendor
    2023-10-26T05:47:00.1233333+00:00

    Hi @Joseph Hedbon,

    You just need to set AutoPostBack="true" in DropDownList1.

     <asp:DropDownList ID="DropDownList1" runat="server" Style="z-index: 1; left: 120px; top: 176px; position: absolute" Font-Bold="True" AutoPostBack="true">
         <asp:ListItem Value="0">Whole Life</asp:ListItem>
         <asp:ListItem Value="1">Term</asp:ListItem>
     </asp:DropDownList>
    

    1

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful