Call AjaxFileUpload OnUploadComplete event on another Button click event using C# and jQuery in ASP.Net

Last Reply 11 months ago By Andrea

Posted 11 months ago

i have this ajax file upload contorl it works fine

what i want is instead of upload file on ajax control blue button i want to upload file on seperate button like 

i have this button on my page

 <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

so in its click event i want to fire ajax file upload event, please adivce

        font-size: 0px;
        font-size: 0px;
        font-size: 0px;
<%@ register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="ajaxToolkit" %>
<ajaxToolkit:AjaxFileUpload ID="AjaxFileUpload11" runat="server" MaximumNumberOfFiles="1"
    Width="400px" OnUploadComplete="OnUploadComplete" OnClientUploadCompleteAll="uploadcompleteAll"
    OnClientUploadError="uploadError" OnClientUploadStart="uploadstart" />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:Image ID="imgDisplay" runat="server" CssClass="image-s" />
<asp:Label ID="lblerror" runat="server" Text="" ForeColor="red"></asp:Label>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
<asp:Button ID="btnUpload" Text="Upload" runat="server" CausesValidation="false"
    OnClick="Upload" Style="display: none" />
<script type="text/javascript">
    function uploadComplete(sender) {
        var imgDisplay = document.getElementById("<%=imgDisplay.ClientID %>");
        imgDisplay.src = "images/loader.gif"; = "";
        var img = new Image();
        img.onload = function () {
   = "height:100px;width:100px";
            imgDisplay.src = img.src;
        img.src = "<%=ResolveUrl(UploadFolderPath) %>" + args.get_fileName();
    function uploadError(sender) {
        $get("<%=Label1.ClientID%>").innerHTML = sender.innerHTML();

    function uploadcompleteAll(sender) {
        alert("successfully uploaded All Files!");
    function uploadstart() {
        alert("File upload started, please wait while we are processing.");


protected void OnUploadComplete(object sender, AjaxFileUploadEventArgs e)
    string myId = IDd;
    string acfilename = Path.GetFileName(e.FileName);
    string fileName = Path.GetFileName(e.FileName);
    string ext = Path.GetExtension(e.FileName);
    fileName = Guid.NewGuid().ToString() + ext;
    Session["f"] = fileName;
    AjaxFileUpload11.SaveAs(Server.MapPath("~/DynamicImages/" + fileName));
    UploadFolderPath = "~/DynamicImages/" + fileName;


Posted 11 months ago