ASP.NET - 重新加载下拉菜单?
我有一个显示文件名的下拉菜单,当索引更改时,将提供所选文件供下载。我还有一个创建新文件的按钮...现在创建新文件后,新文件名也应该显示在下拉列表中。当我刷新页面时,它工作正常,但这不是我想要的。
我尝试将下拉菜单放入更新面板并为其提供文件创建按钮 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您在同一页面中创建文件,则只需将文件名附加到下拉列表中即可。你能在你的应用程序中做到这一点吗?
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?
您是否按下回帖按钮?如果是,那么您需要在按钮单击处理程序中创建文件后再次重新绑定下拉列表。
如果按钮对服务器进行部分回发(假设它放置在 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.
您需要确保按钮是更新面板的触发器,或者是其中的子按钮。
这是完整的解释:
http://www.asp.net/ajax/tutorials/understanding-asp-net-ajax-updatepanel-triggers" rel="nofollow noreferrer"> asp.net/ajax/tutorials/understanding-asp-net-ajax-updatepanel-triggers
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
您需要将该按钮放置在 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.