Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
493 views
in Technique[技术] by (71.8m points)

asp.net - Can't get AsyncFileUpload to work in update panel

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

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %> 
<asp:ScriptManager ID="ScriptManager2" runat="server" ></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <cc1:AsyncFileUpload ID="AsyncFileUpload2" runat="server" />
        <asp:LinkButton id="lbSubmitOrder" runat="server" title="Submit Order Request" class="btn_blue_dynamic_med"/>
    </ContentTemplate>      
</asp:UpdatePanel>

In my code behind:

 Dim path As String = Server.MapPath("~/temp/test.tmp")

 AsyncFileUpload2.SaveAs(path)

In my AsyncFileUpload2 object the filename is nothing. I can't seem to get a refernce to the file that is supposed to be uploaded.

-Nate

UPDATE
I've added

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

I can't hit a break point at the "if" statement after I choose a file. I guess there is something wrong on my page with how ajax is working? Not sure what it is though.

FIXED!
I was displaying the ajax upload box via a radio button with a visible=true/false div. The answer told me that the control has to be there the page loads. I took away the div and everything worked! I will now do the show/hide through jquery (which I should have done in the first place).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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">

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...