简体   繁体   中英

ASP.Net DropDownList SelectedIndexChanged Event fires but does nothing

I have the following ASP.Net code:

code.aspx:

<asp:UpdatePanel ID="upMain" runat="server">
    <ContentTemplate>
        <table>
          <tr>
            <td>DropDownList One</td>
            <td>
                <asp:DropDownList ID="ddlOne" runat="server" AutoPostBack="true"
                    OnSelectedIndexChange="ddlOne_SelectedIndexChanged" />
            </td>
            <td>DropDownList Two</td>
            <td>
                <asp:DropDownList ID="ddlTwo" runat="server" />
            </td>
          </tr>
        </table>
    </ContentTemplate>
</asp:UpdatePanel>

code.aspx.cs:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
       ddlTwo.Visible = false;
    }
}

protected void ddlOne_SelectedIndexChanged(object sender, EventArgs e)
{
    ddlTwo.Visible = true;
}

What I Expect:

This code is supposed to make ddlTwo visible upon ddlOne 's selected index changing.

What Actually Happens:

Upon changing the index of ddlOne , the ddlOne_SelectedIndexChanged function runs (test with debug) and the ddlTwo.Visible = true; runs too but the and the property is changed as I step through the process but the moment the function is over and I want to see my results (ie the visible ddlTwo control), there's no result.

If anyone can spot the issue, please let me know. Thank you!

try

<Triggers>
    <asp:AsyncPostBackTrigger ControlID="ddlOne" 
    EventName="SelectedIndexChanged" />
</Triggers>

inside update panel.

Change this line

OnSelectedIndexChange="ddlOne_SelectedIndexChanged"

to

OnSelectedIndexChanged="ddlOne_SelectedIndexChanged"

and it should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM