开发者

File upload control - Select file is lost when 2nd control is initiatied

Our problem/question revolves around an upload control that loses the selected file (goes blank) when a postback control is used (in this case, the dropdown list posts). Any insight into what we are doing wrong or how we can fix this? Below is our code and a summary of the problem.

Any help would be greatly appreciated.

Thank you!

<asp:updatepanel id="UpdatePanel1" runat="server">
                       <ContentTemplate>
                              <div class="row">
                                     <asp:DropDownList runat="server" AutoPostBack="true" ID="CategorySelection" OnSelectedIndexChanged="CategorySelection_IndexChanged" CssClass="drop-down-list" />
                              </div>
                              <div id="SubCategory" class="row" runat="server" visible="false">
                                     <asp:DropDownList runat="server" ID="SubCategorySelection" CssClass="drop-down-list" />
                              </div>
                           开发者_运维百科   <div class="row">
                                     <asp:FileUpload runat="server" ID="FileUpload" CssClass="file-upload" />
                              </div>
                              <div class="row">
                                     <asp:Button ID="submit" runat="server" Text="Submit" CssClass="button" OnClick="submit_ButtonClick" />
                              </div>
                       </ContentTemplate>
                       <Triggers>
                              <asp:PostBackTrigger ControlID="submit" />
                       </Triggers>
                 </asp:updatepanel>

In this form we have 2 DropDownList, 1 FileUpload and 1 submit button. Every time that the user selects one category, the subcategories are loaded (AutoPostBack=”true”).

The primary user flow works fine: User selects one category, subcategory and selects a file to be uploaded (submitted). HOWEVER, if the user selects a file first, and then selects a category, the screen will do a partial refresh and the selected file will disappear (field goes blank). As a result, the user needs to select the file again. This causes an issue because the fact that the file is no longer selected can easily be overlooked.

Seems straighforward --- but causing us a lot of grief. Any experts out there that can help?

BIG thanks!


That is the behavior of the input type=file i.e. it can't be pre-populated. Move the FileUpload outside of the UpdatePanel. In your markup, you could move both FileUpload and the submit Button outside of the UpdatePanel.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜