FileUpload uploads twice

Posted by Sharpcnet under ASP.NET on 3/16/2014 | Points: 10 | Views : 2338 | Status : [Member] | Replies : 1
This is what I'm trying to do. When an image is uploaded using Ajax AsyncFilepload, it also shows the image in the Image Control. Since, the upload is asynchronous, though the image uploads fine, it doesnt show in the image Control. So, following a suggestion, added the JS function. It works fine now, but just that the C# code fires twice, because of the postback and hence every Image is uploaded twice.

Also, why is the ViewState becoming null, the second time. This page uses a master.

JS :

function UpdateImage()


<asp:AsyncFileUpload ID="fu" runat="server" 
OnClientUploadComplete="UpdateImage" OnUploadedComplete="fu_UploadedComplete"/>

<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<asp:Image runat="server" ID="img"/>

C# :

protected void fu_UploadedComplete(object sender, 
AjaxControlToolKit.AsyncFileUploadEventArgs e)
if(fu.HasFile && ViewState["vMap"] == null)
string sNew = getRandomNumber().ToString() + fu.FileName;
ViewState["vMap"] = sNew;
sNew = "~/Temp/"+sNew;
img.ImageUrl = sNew;


Posted by: Allemahesh on: 3/18/2014 [Member] [MVP] Silver | Points: 25

Login to post response