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

 Posted on 10/16/2019

Hi,

need help to upload images by drag and drop in asp.net c# on asp button click have tried with ajax upload but no go.

the ajax uploadfile has its own upload button but i need to do it on asp button.

Share On: facebook gplus twitter
profile
Asked by Walter Tross on 10/16/2019 Score: 24 points
Add Comment:

Comments

2 Answers

0 Corrected Answers
Aproved Answers
0
Profile
Answered by hardik chaudhary on 10/21/2019 8:14:08 AM Score: 553 points

hi thank you for your help.

it is working fine as expected however i used ur logic in a diff way

function validate() {

       if ($(".ajax__fileupload_fileItemInfo").length > 0) {

           alert('file exist');

           // $('.ContentPlaceHolder1_AjaxFileUpload1_UploadOrCancelButton').hide();

           //$("[id$=AjaxFileUpload1_UploadOrCancelButton]").click();

           $(".ajax__fileupload_uploadbutton").trigger("click");

           alert("Hiiii");

           return true;

       }

 

       else {

           alert('select your file');

           return false;

       }

   };

and called it on button client upload.

Comments

Add Comment:
Aproved Answers
0
Profile
Answered by Helder Sepulveda on 10/16/2019 9:07:53 AM Score: 58 points

Check with below:

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        body
        {
            font-family: Arial;
            font-size: 10pt;
        }
    </style>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ToolkitScriptManager runat="server">
    </asp:ToolkitScriptManager>
    <asp:AjaxFileUpload ID="AjaxFileUpload11" runat="server" MaximumNumberOfFiles="5"
        Width="400px" OnUploadComplete="OnUploadComplete" />
    <asp:Button Text="Save" runat="server" OnClick="Save" />
    <input type="submit" value="Custom Upload Button" runat="server" onserverclick="Save"
        onclick="$('.ajax__fileupload_uploadbutton').trigger('click');" />
    </form>
</body>
</html>

 

protected void OnUploadComplete(object sender, AjaxFileUploadEventArgs e)
{
    string fileName = Path.GetFileName(e.FileName);
    AjaxFileUpload11.SaveAs(Server.MapPath("~/Uploads/" + fileName));
}

protected void Save(object sender, EventArgs e)
{        

}

But Button click event is raised first and then OnUploadComplete event will be raised.

Comments

Add Comment:

Post Your Answers

Existing Members

Sign in to your account
Email Address
Password
New Member?
Sign up and complete profile
Full Name
Email Address
I have read and agree to the Terms of Service and Privacy Policy
Please subscribe me to the StoodQ newsletters
Guideline to answer a question:

Useful tips to submit your answer
Please read below guidelines before you submit your answer for question.

  • Read and understand question for which you are submitting your answer.
  • Try to avoid grammatical and spell mistake while answering.
  • Do not post any irrelevant information in your answer.
  • Explain your answer with example or any reference link to help who posted question.
  • If you find irrelevant question, please report it to support. Click here to contact support.
  • You agree to the privacy policy and terms of use to submit any contents.

Note: StoodQ is online developers community which helps developer for their difficulty, lets help them with your value contribution.