Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Ajax FileUpload Control - trigger Upload event

$
0
0

First off, good day to all who see this.

I am fairly new to C# and .Net coding, so please be gentle.  And if there is something with my issue that seems too basic for me to get it wrong, don't be so sure ;)

I am attempting to use the AjaxFileUpload control to allow users to upload multiple files associated to an issue created in my web app.  To accomplish this, I need the user to fill out the form presented, and then place any files they want uploaded into the control.  The trick is, I need to perform some additional work between the time they press the submit bottun and the time the file(s) are uploaded.

So my thought was to remove the Upload button associated with the FileUpload control, and trigger the event it starts from my own Submit button.  I have figured out how to remove te Upload button, but not how to to trigger the event in my C# code.

Definition of my control:

<asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server" style="z-index: 1; left: 170px; top: 570px; position: absolute;"
            AllowedFileTypes="jpg,jpeg,doc,docx,xls,xlsx,pdf,txt,tif,wps,image" MaximumNumberOfFiles="5"
            onuploadcomplete="AjaxFileUpload1_UploadComplete"
            ThrobberID="MyThrobber" CssClass="AjaxFileUpload1" />

Hiding the button:

#AjaxFileUpload1_UploadOrCancelButton{
display: none;
}

Upload Complete event:

    protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
    {
        if (!System.IO.Directory.Exists(Server.MapPath(@"~/" + Global.IssueID.ToString() + "/")))
        {
            System.IO.Directory.CreateDirectory(Server.MapPath(@"~/" + Global.IssueID.ToString() + "/"));
        }
        string filePath = Server.MapPath("~/" + Global.IssueID.ToString() + "/") + "Issue " + Global.IssueID.ToString() + " " + e.FileName;
        AjaxFileUpload1.SaveAs(filePath);
    }

When pressing the Submit button, validation of the form occurs, then the issue is created in the database, and an IssueID is returned.  At that point I want to trigger the Upload event, and have the UploadComplete event fire normally, modifying the filename as shown above.

Any insight into how to trigger that upload event would much appreciated.

Thanks for your time.


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>