Async File upload with jquery and handler in asp.net

Jul 7 2019 2:12 AM
Hi i want to implement async Fileupload in asp.net with jquery.
 
When i will upload that time i have to submit others textbox vaue also.
 
So to do that i am using the logic ...
 
first i will upload the file and it will save to server then in final submit button i will send the form data and uploaded file name with service.
 
Frist of all i dnt want to refresh my page so i want to use Ajax tookit async fileupload control.
 
After file upload i want to get file name as response so that in final submit button i can send the form data and file name as well.
 
I have written code but im facing problem.
 
whever response im getting i am writting that in a label and that label value i want in backend .
 
but that labe value is empty always i dnt know why it is....
 
Here is the code..........................
  1. <script type="text/javascript">  
  2. function uploadComplete(sender, args) {  
  3. $get("<%=Label1.ClientID%>").innerHTML = args.get_fileName();  
  4. }  
  5. </script>  
aspx code
  1. <form id="form1" runat="server">  
  2. <asp:ScriptManager ID="ScriptManager1" runat="server">  
  3. </asp:ScriptManager>  
  4. <h3>File upload control</h3>  
  5. <div>  
  6. <table border="1" cellpadding="1" cellspacing="0">  
  7. <tr>  
  8. <td>  
  9. Name :  
  10. </td>  
  11. <td>  
  12. <input type="text" id="name" />  
  13. </td>  
  14. </tr>  
  15. <tr>  
  16. <td>  
  17. Photo :  
  18. </td>  
  19. <td>  
  20. <ajaxToolkit:AsyncFileUpload ID="AsyncFileUpload1" runat="server" OnClientUploadComplete="uploadComplete"  
  21. OnUploadedComplete="AsyncFileUpload1_UploadedComplete" UploaderStyle="Modern" />  
  22. </td>  
  23. </tr>  
  24. </table>  
  25. <br />  
  26. <asp:Label ID="Label1" runat="server"></asp:Label>  
  27. </div>  
  28. <div>  
  29. <asp:Button Text="Save" ID="btnSave" runat="server" OnClick="btnSave_Click" />  
  30. <asp:Button Text="Cancel" ID="btnCancel" runat="server" OnClick="btnCancel_Click" />  
  31. </div>  
  32. </form>  
C# code
  1. protected void Page_Load(object sender, EventArgs e)  
  2. {  
  3. }  
  4. protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)  
  5. {  
  6. AsyncFileUpload1.SaveAs(Server.MapPath("~/Temp/") + Path.GetFileName(AsyncFileUpload1.FileName));  
  7. }  
  8. protected void btnSave_Click(object sender, EventArgs e)  
  9. {  
  10. }  
  11. protected void btnCancel_Click(object sender, EventArgs e)  
  12. {  
  13. string file = Label1.Text;  
  14. }  
Problem 1:
 
I want to get file name in btnCancel_Click but now it coming empty.
 
here i will delete the file if user cancle the form.
 
Problem 2:
 
If i click to btnCancel_Click then after complete this form again control coming to AsyncFileUpload1_UploadedComplete this function. (C#)
i don't want that.
 
Problem 3:
 
I want to use generic handler how to use that?
Someone help me please! if you dnt understand the you can ask me again.
Last 3 days im stuck in file upload control.
Remember it is not MVC application it is asp.net application.
I want to implement async file uploader.
I dnt want to use extra button to save a file.
Its a single file uploader control.
I dnt to do maximum this in client side and upload and file save should handle by handler.
I serch lot i did not get actual solution.
If you have any other idea then you are welcome.
Thank you in advance.

Answers (1)