views:

66

answers:

5

Hello, 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!

A: 

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?

Siva Gopal
A: 

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.

VinayC
Rebinding doesnt work, it will add it to the dropdown, yes, but the item is not shown until a page refresh takes place.
grady
How about putting button and drop-down in same UpdatePanel? If your button is outside then does it do normal post-back or partial post-back?
VinayC
A: 

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

TimS
I tried, but I get this message: **Control with ID '...' being registered through RegisterAsyncPostBackControl or RegisterPostBackControl must implement either INamingContainer, IPostBackDataHandler, or IPostBackEventHandler.**Whats wrong with the button? Its an ordinary LinkButton
grady
A: 

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.

El Ronnoco
A: 

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

grady