当我设置一个运行onselectedindexchanged的函数时,我的程序只是忽略该命令

时间:2012-11-26 20:59:36

标签: c# asp.net code-behind

我正在制作一个网页。这里的目标是从下拉列表中选择文件时打开文件。这是我现在遇到的故障代码:

<asp:DropDownList ID="dropdownFiles" runat="server" Height="18px" onselectedindexchanged="File_Opener" Width="380px">
                <asp:ListItem>Please choose a file...</asp:ListItem>
</asp:DropDownList>

看到“onselectedindexchanged”部分?在代码隐藏中,我有以下功能:

public void File_Opener(object sender, EventArgs e)
    {
        //here's where I would open the files, but it never even hits this function!
    }

出于某种原因,在下拉列表中选择某些内容甚至不会触发该功能。 plsexplain。

4 个答案:

答案 0 :(得分:2)

我认为你需要将下拉列表设置为autopostback。

答案 1 :(得分:1)

打开文件或对选择进行操作是一种糟糕的用户体验,为什么???因为我可能认为我正在选择文件名并单击错误的文件名。在选择文件后,最好有一个按钮来启动你想要做的任何过程。

答案 2 :(得分:0)

使用AutoPostBack属性:

<asp:DropDownList ID="dropdownFiles" runat="server" Height="18px" onselectedindexchanged="File_Opener" Width="380px" AutoPostBack="True">
                <asp:ListItem>Please choose a file...</asp:ListItem>
</asp:DropDownList>

答案 3 :(得分:0)

幽默我:尝试在OnSelectedIndexChanged上使用合适的外壳。看看是否有所作为。