DropDownList的SelectedIndexChanged事件不触发 [英] DropDownList's SelectedIndexChanged event not firing

查看:198
本文介绍了DropDownList的SelectedIndexChanged事件不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是网络上频繁的问题,尽管没有一个答案似乎已经帮助。

This seems to be a frequent issue around the web, although none of the answers seem to have helped.

我在我的网页一个DropDownList对象。当我点击它,选择不同的值,什么都不会发生,即使我有连接到的SelectedIndexChanged 事件的函数。我会试着在这里发表我的code作为有序地:

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. I'll try and post my code here as orderly as possible:

首先,实际对象的HTML code:

First, the actual object's HTML code:

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

和这是一个功能, 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>");
        }
    }
}

在回应中没有出现,和JavaScript的那部分永远不会运行。我试过这个最新的3.6版本的Firefox,以及Internet Explorer 8中这是正在从Windows Server服务2003 R2的机器,使用.NET Framework版本上运行ASP.Net 4。

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.

如果有人可以帮助,那将是巨大的。

If anyone can help, that would be great.

推荐答案

设置DropDownList的的AutoPostBack 属性设置为true。

Set DropDownList AutoPostBack property to true.

例如:

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

这篇关于DropDownList的SelectedIndexChanged事件不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆