upload file not working in updatepanel

前端 未结 3 1730
[愿得一人]
[愿得一人] 2021-01-13 17:08

I DONT WANNA GET MY PAGE TO BE GET REFRESH OR POSTBACK

So I am trying uploading file in updatepanel but onclicking upload button the valida

相关标签:
3条回答
  • 2021-01-13 17:55

    Write trigger will instruct the button that we are using for the upload to perform a full postback

    <asp:UpdatePanel ID="UpdatePanel16" runat="server">
    <Triggers>
        <asp:PostBackTrigger ControlID="btn_browse" />
           </Triggers>
    <ContentTemplate>
     <asp:FileUpload ID="fp_upload" runat="server" />&nbsp;&nbsp;
    <asp:Button ID="btn_browse" runat="server" Text="Upload" OnClick="btn_browse_Click" />
        </ContentTemplate>  
        </asp:UpdatePanel>
    
    0 讨论(0)
  • 2021-01-13 17:56

    just add PostBackTrigger after </ContentTemplate> for the FileUploader as below:

     </ContentTemplate>
          <Triggers>
          <asp:PostBackTrigger ControlID="FileUpload1" /> 
         </Triggers>
     </asp:UpdatePanel> 
    

    and add the below code in page load :

    ScriptManager.GetCurrent(this).RegisterPostBackControl(FileUpload1);  
    

    or if you want to make it async, you can use this :

    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:FileUpload ID="FileUpload1" runat="server" />
            <asp:Button ID="btnAsyncUpload" runat="server"
               Text="Async_Upload" OnClick = "Async_Upload_File" />
            <asp:Button ID="btnUpload" runat="server" Text="Upload"
               OnClick = "Upload_File" />               
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID = "btnAsyncUpload"
              EventName = "Click" />
            <asp:PostBackTrigger ControlID = "btnUpload" />
        </Triggers>
    </asp:UpdatePanel>
    
    0 讨论(0)
  • 2021-01-13 18:06

    To use a FileUpload control inside an UpdatePanel control, set the postback control that submits the file to be a PostBackTrigger control for the panel.

    0 讨论(0)
提交回复
热议问题