ASP.NET - 重新加载下拉菜单?

发布于 2024-09-24 04:15:02 字数 796 浏览 0 评论 0原文

我有一个显示文件名的下拉菜单,当索引更改时,将提供所选文件供下载。我还有一个创建新文件的按钮...现在创建新文件后,新文件名也应该显示在下拉列表中。当我刷新页面时,它工作正常,但这不是我想要的。

我尝试将下拉菜单放入更新面板并为其提供文件创建按钮 ID,但失败了...这是正确的方法还是有更简单的方法?

谢谢!


我只是无法让它工作,这是我的代码:

<asp:UpdatePanel ID="UP_ExportInvoices" runat="server" UpdateMode="Always">
     <ContentTemplate>
         <asp:DropDownList ID="DDL_ExportFileDownLoad" runat="server" AutoPostBack="true"
                        OnSelectedIndexChanged="DDL_ExportFileDownLoad_SelectedIndexChanged">
         </asp:DropDownList>
     </ContentTemplate>
</asp:UpdatePanel>

我在想,如果 UpdateMode 设置为 Always,内容总是会更新吗?我还有那个按钮(asp:ImageButton),它位于此 UpdatePanel 之外。我尝试添加一个触发器 fpr 该按钮,但它不起作用。我做错了什么。到目前为止,我仅抛出异常或下拉列表未更新。

谢谢 :)

I have a dropdown which shows filesnames and when the index is changed, the slected file is offered for download. I also have a button which creates new files ... now after a new file was created, the new filename should also be shown in the dropdown. It works fine, when I refresh the page, but this is not what I want.

I tried putting the dropdown in an updatepanel and giving it the file create button id, it failed ... is this the correct apporach or is there an easier way?

Thanks!


I just cant get it to work, this is my code:

<asp:UpdatePanel ID="UP_ExportInvoices" runat="server" UpdateMode="Always">
     <ContentTemplate>
         <asp:DropDownList ID="DDL_ExportFileDownLoad" runat="server" AutoPostBack="true"
                        OnSelectedIndexChanged="DDL_ExportFileDownLoad_SelectedIndexChanged">
         </asp:DropDownList>
     </ContentTemplate>
</asp:UpdatePanel>

I was thinking that if the UpdateMode is set to Always, that the content is always updated? I also have that button (asp:ImageButton) which resides outisde this UpdatePanel. I tried adding a Trigger fpr that button, but it did not work. What am I making wrong. So far, im only thrwoing exceptions or the dropdown is not updated.

Thanks :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

姐不稀罕 2024-10-01 04:15:02

如果您在同一页面中创建文件,则只需将文件名附加到下拉列表中即可。你能在你的应用程序中做到这一点吗?

If you are creating the file in the same page, then just append the file name to the dropdown. Can you do this trick in your application?

北城挽邺 2024-10-01 04:15:02

您是否按下回帖按钮?如果是,那么您需要在按钮单击处理程序中创建文件后再次重新绑定下拉列表。

如果按钮对服务器进行部分回发(假设它放置在 UpdatePanel 中),则上述内容仍然适用,但下拉菜单也应该位于 UpdatePanel 中。

Does you button posts back the page? If yes, then you need to rebind the drop-down again after you create the file in button click handler.

If button makes partial post-back (say it is placed within UpdatePanel) to the server then above will be still applicable but dropdown should also be in UpdatePanel.

比忠 2024-10-01 04:15:02

You need to ensure that the Button is a trigger for the Update Panel, or is a child within it.

Here is a full explanation:

http://www.asp.net/ajax/tutorials/understanding-asp-net-ajax-updatepanel-triggers

站稳脚跟 2024-10-01 04:15:02

您需要将该按钮放置在 UpdatePanel 中。这将导致部分回发,并且下拉列表应重新绑定,显示新项目。或者,您可以在页面中包含 JavaScript,将新项目添加到客户端的下拉列表中,但这有时会导致 ASP 的自动事件验证出现问题。

You need to place the button within the UpdatePanel. This will cause a partial postback and the dropdown should re-bind, showing the new item. Alternatively you can include JavaScript in your page which adds the new item to the dropdown list on the client-side, however this can sometimes cause problems with ASP's automatic event validation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文