Can't get AsyncFileUpload to work in update panel

后端 未结 4 1023
广开言路
广开言路 2020-12-06 13:53

I have a user control with a updatepanel, script manager and a asyncfileupload control.

<%@ Register Assembly=\"AjaxControlToolkit\" Namespace=\"AjaxContr         


        
相关标签:
4条回答
  • 2020-12-06 14:33

    In case this helps someone, I fixed my problem by adding the following to the form tag:

    enctype="multipart/form-data" method="post"
    
    0 讨论(0)
  • 2020-12-06 14:34

    Make sure that the usercontrol with asyncfileupload control is not loaded asynchronously, for example via Response.Redirect("pageWithUploadControl").

    Have you handled the FileUploadComplete Event and checked if AsyncFileUploadState is Success?

       Private Sub AsyncFileUpload1_UploadedComplete(ByVal sender As Object, ByVal e As AjaxControlToolkit.AsyncFileUploadEventArgs) Handles AsyncFileUpload1.UploadedComplete
            If e.state = AjaxControlToolkit.AsyncFileUploadState.Success Then
                '....'
            Else
                showErrorMessage(e)
            End If
        End Sub
    
        Private Sub showErrorMessage(ByVal e As AjaxControlToolkit.AsyncFileUploadEventArgs)
            Dim message As String = String.Empty
            Select Case e.statusMessage
                Case AjaxControlToolkit.AsyncFileUpload.Constants.Errors.EmptyContentLength
                    message = "Empty content length!"
                Case AjaxControlToolkit.AsyncFileUpload.Constants.Errors.FileNull
                    message = "Fill NULL!"
                Case AjaxControlToolkit.AsyncFileUpload.Constants.Errors.InputStreamNull
                    message = "Input Stream NULL!"
                Case AjaxControlToolkit.AsyncFileUpload.Constants.Errors.NoFileName
                    message = "No File Name!"
                Case AjaxControlToolkit.AsyncFileUpload.Constants.Errors.NoFiles
                    message = "No Files!"
            End Select
            LblMessage.Text = message 
        End Sub
    

    Try to change change the enctype of your form:

    <form id="form1" enctype="multipart/form-data" runat="server">
    
    0 讨论(0)
  • 2020-12-06 14:45

    I was having the same problem, read and tried countless posts on how to fix it (obviously a lot of people are having this issue) but nothing worked. Until I replaced the ScriptManager with the ToolkitScriptManager
    Change:

    <asp:ScriptManager ID="ScriptManager2" runat="server" ></asp:ScriptManager>
    

    with:

    <cc1:ToolkitScriptManager ID="ScriptManager2" runat="Server" />
    

    I am not sure if this is requirement on the latest tool kit (December 2013), but it worked for me. Hopefully it will help someone else too.

    0 讨论(0)
  • 2020-12-06 14:53

    Hi you can do it by using OnUploadedComplete="AsyncFileUploadPDF_UploadedComplete" in .cs file add

    protected void AsyncFileUploadPDF_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
            {
                if (AsyncFileUploadImage.HasFile)
                {
                    Session["AsyncFileUploadPDF"] = AsyncFileUploadImage;
                }
            }
    

    and you can get data from session where ever you want as I get on click event of button

    protected void btnSaveParts_Click(object sender, EventArgs e)
            {
                AsyncFileUploadPDF = (AsyncFileUpload)Session["AsyncFileUploadPDF"];
                PdfFileName = AsyncFileUploadPDF.FileName;         
            }
    
    0 讨论(0)
提交回复
热议问题