开发者

ASP.NET - reload a dropdown?

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 :)


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?


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜