0

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

<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!
    }

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

4

4 回答 4

2

我认为您需要将下拉菜单设置为自动回发。

于 2012-11-26T21:01:39.513 回答
1

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

于 2012-11-26T22:19:43.863 回答
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>
于 2012-11-26T21:06:46.243 回答
0

幽默我:尝试在OnSelectedIndexChanged. 看看这是否有所作为。

于 2012-11-26T22:27:28.803 回答