Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a DropDownList object in my web page. When I click on it and select a different value, nothing happens, even though I have a function wired up to the SelectedIndexChanged event.

First, the actual object's HTML code:

<asp:DropDownList ID="logList" runat="server" 
       onselectedindexchanged="itemSelected">
</asp:DropDownList>

And this is that function, itemSelected:

protected void itemSelected(object sender, EventArgs e)
{
    Response.Write("Getting clicked; " + sender.GetType().ToString());
    FileInfo selectedfile;
    Response.Write("<script>alert('Hello')</script>");
    foreach (FileInfo file in logs)
    {
        if (file.Name == logList.Items[logList.SelectedIndex].Text)
        {
            Response.Write("<script>alert('Hello')</script>");
        }
    }
}

None of the Responses appear, and that portion of JavaScript is never run. I've tried this on the latest 3.6 version of Firefox, as well as Internet Explorer 8. This is being served from a Windows Server 2003 R2 machine, running ASP.NET with the .NET Framework version 4.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.4k views
Welcome To Ask or Share your Answers For Others

1 Answer

Set DropDownList AutoPostBack property to true.

Eg:

<asp:DropDownList ID="logList" runat="server" AutoPostBack="True" 
        onselectedindexchanged="itemSelected">
    </asp:DropDownList>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...