locked
AjaxFileUpload see if files are waiting in the queue to be uploaded RRS feed

  • Question

  • User602299069 posted

    I'm using AjaxFileUpload in a small ASP.Net Web Forms project and it's working well. My application has a few text fields, check boxes, the uploader and a Submit button. When the user clicks the Submit button I need to be able to check the AjaxFileUpload control to see if there are any selected files in pending state and if there are I want to alert the user that there are files waiting to be uploaded. I can't seem to find a way to do this. I need this to happen in the code behind. I know that in the UploadStarted and UploadComplete event I can check "FilesInQueue" but I'm hoping there is a way to check the queue before the user has actually initiated the upload.

    Thank you

    Tony

    Saturday, September 21, 2019 6:58 PM

Answers

  • User665608656 posted

    Hi tmott,

    According to your description, I recommend that you can try to use session to record the state of the upload Files.

    And you need to put your submit button in updatepanel to avoid page refreshing.

    For more details, you could refer to the following code:

    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title> 
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
                <ajaxToolkit:AjaxFileUpload ID="AjaxFileUpload1" OnUploadCompleteAll="AjaxFileUpload1_UploadCompleteAll" Mode="Auto" runat="server" />
                <br />
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />
                    </ContentTemplate>
                </asp:UpdatePanel>
            </div>
        </form>
    </body>
    </html>
       protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    Session["UploadState"] = "start";
                }
            }
    
    
            protected void Button1_Click(object sender, EventArgs e)
            {
                if (Session["UploadState"].ToString() != "UploadAll")
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "img", "alert('Please upload files first!')",true);
                   
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "img", "alert('submit successfully!');", true);
    // do something you want when submit successfully Session["UploadState"] = "start"; } } protected void AjaxFileUpload1_UploadCompleteAll(object sender, AjaxControlToolkit.AjaxFileUploadCompleteAllEventArgs e) { Session["UploadState"] = "UploadAll"; }

    Here is the result of this work demo:

    Best Regards,

    YongQing.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 23, 2019 8:02 AM