Click here to Skip to main content
15,890,434 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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....


What I have tried:

<script type="text/javascript">
function uploadComplete(sender, args) {
$get("<%=Label1.ClientID%>").innerHTML = args.get_fileName();
}
</script>
 
 
 
aspx code================== =======
 
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<h3>File upload control</h3>
<div>
<table border="1" cellpadding="1" cellspacing="0">
<tr>
<td>
Name :
</td>
<td>
<input type="text" id="name" />
</td>
</tr>
<tr>
<td>
Photo :
</td>
<td>
<ajaxToolkit:AsyncFileUpload ID="AsyncFileUpload1" runat="server" OnClientUploadComplete="uploadComplete"
OnUploadedComplete="AsyncFileUpload1_UploadedComplete" UploaderStyle="Modern" />
</td>
</tr>
</table>
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
</div>
<div>
<asp:Button Text="Save" ID="btnSave" runat="server" OnClick="btnSave_Click" />
<asp:Button Text="Cancel" ID="btnCancel" runat="server" OnClick="btnCancel_Click" />
</div>
</form>
 
C# code================================ 
 
protected void Page_Load(object sender, EventArgs e)
{
}
protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
AsyncFileUpload1.SaveAs(Server.MapPath("~/Temp/") + Path.GetFileName(AsyncFileUpload1.FileName));
}
protected void btnSave_Click(object sender, EventArgs e)
{
}
protected void btnCancel_Click(object sender, EventArgs e)
{
string file = Label1.Text;
}
 
 
======================================
 
 
Probelm 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 calick to btnCancel_Click then after complete this form again contorl coming to  AsyncFileUpload1_UploadedComplete this function. (C#)
 
i dnt want that. 
 
Probelm 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 cntrol.
 
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 handel by handler.
 
I serch lot i did not get actual soluation.
 
If you have any other idea then you are welcome.
 
Thnak you in advance. 
Posted
Updated 27-Aug-19 10:40am

1 solution

You can use Dropzone Js it's a good one for ajax based async file uploading

Read this article for details and stackoverflow answers as well.

Asp.net C# + Dropzone js : Easy Way to Upload Images [Drag & Drop Feature] | Codepedia[^]

asp.net - using dropzone.js in webform with master page - Stack Overflow[^]

c# - Using dropzone.js in asp.net - Stack Overflow[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900