Download failed once then works correctly

I am working on a custom ASP.Net element. In my control, I have a FileUpload control inside a MultiView inside an AJAX UpdatePanel.

I added a submit button to the update panel feedback triggers. (This is the standard patch for FileUpload in UpdatePanel).

The first time FileUpload is sent, it does not load anything (i.e., the FileBytes property of the control is zero length). Everything else in the form is sent correctly.

In the second and subsequent representations, loading is performed correctly.

What could be the reason for this and how to fix it?


For example:

<asp:UpdatePanel runat="server" ID="update_panel" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:MultiView runat="server" ID="mvMultiView" ActiveViewIndex="0">
            <asp:View runat="server" ID="viewOne">
                <!-- content -->
            </asp:View>
            <asp:View runat="server" ID="viewTwo">
                <!-- some other form elements -->
                <asp:FileUpload ID="file_upload" runat="server" />
                <asp:Button ID="save_button" runat="server" Text="Save" OnClick="save_Click" ValidationGroup="group" />
            </asp:View>
         </asp:MultiView>
    </ContentTemplate>
    <Triggers>
        <asp:PostBackTrigger ControlID="save_button" />
    </Triggers>
</ajax:UpdatePanel>
+3
source share
5

, FileUpload . FileUpload . submit , .

: , , .

:

   <Triggers>
      <asp:PostBackTrigger ControlID="btnShowUploadForm" />
      <asp:PostBackTrigger ControlID="btnUpload" />
   </Triggers>                            
+2

FileUpload , UpdatePanel.

AJAX. Telerik , , . , , . .

+1

, , , UpdateMode = Conditional:

  <asp:UpdatePanel ID="upUpload" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
    <asp:RadioButton ID="rbImage" GroupName="resourceupload" Checked="true" Text="image" runat="server" />
    <asp:RadioButton ID="rbPdf" GroupName="resourceupload" Text="pdf" runat="server" />
     <asp:FileUpload ID="FileUpload1" runat="server"  Width="175"/>
    <asp:Button ID="btnUpload" runat="server" CausesValidation="false"
    Text="Upload" OnClick="btnUpload_Click" />
    <asp:Label ID="lblMsg" Visible="false" runat="server" Text=""></asp:Label>

    </ContentTemplate> 
    <Triggers>
      <asp:PostBackTrigger ControlID="btnUpload" />
      </Triggers>                            
   </asp:UpdatePanel>
+1

" ", .

Page.Form.Enctype = "multipart/form-data";

.

+1

The decision to also add btnShowUploadForm will negate the purpose of the update panel. You can also remove the data access control (where the file upload control is located) from the update panel. The update panel point is for btnShowUploadForm and the Cancel button (to cancel the download, if any) to at least call asynchpostback for better user convenience.

0
source

Source: https://habr.com/ru/post/1722298/


All Articles