8

I am using Ajax AsyncFileUpload in asp.net. It is working fine in uploading image but don't know why it is redirecting to same page with some querystring OnUploadComplete. I don't want to reload page. How to solve this ?

My Code is as below:

function uploadComplete() {
    document.getElementById('<%=lblPhotoUpload.ClientID %>').innerHTML = "Quiz Image Uploaded Successfully.";
     $("#UploadQuizImageProcess").hide();
}

function uploadError() {
     document.getElementById('<%=lblPhotoUpload.ClientID %>').innerHTML = "File Upload Failed.";
     $("#UploadQuizImageProcess").hide();
}
function uploadQuizImageStart() {
     $("#UploadQuizImageProcess").show();
}

<asp:AsyncFileUpload ID="fuPhoto" runat="server" UploadingBackColor="#779ED3" CompleteBackColor="#179406" ThrobberID="imgLoad" OnUploadedComplete="QuizImageUploadComplete" OnClientUploadStarted="uploadQuizImageStart" OnClientUploadComplete="uploadComplete" OnClientUploadError="uploadError" UploaderStyle="Traditional" />
<span id="UploadQuizImageProcess" style="display: none">
<img src="../images/uploading.gif" alt="Upload" /></span>
<asp:Label ID="lblPhotoUpload" runat="server" CssClass="lbler"></asp:Label>

protected void QuizImageUploadComplete(object sender, AsyncFileUploadEventArgs e)
    {
        if (fuPhoto.HasFile)
        {
            string filename = "";
            filename = "quiz" + ".jpg";

            // Save Image
        }
    }
Jeeten Parmar
  • 5,568
  • 15
  • 62
  • 111

3 Answers3

1

is it not per design in asp.net webforms, that a post goes allways back to the same page ?

In your case it goes then in the QuizImageUploadComplete method. So you could do a response.redirect("someulr.aspx") at the end of this method to get to another page

0

The documentation says:

onuploadedcomplete: This is a server side event which will be executed once the uploading is complete. 
Amit Kumar Ghosh
  • 3,618
  • 1
  • 20
  • 24
0

I dont think there is any issue with the code which you have pasted here.

As your control has runat="server" so anyways on uploading a file, a postback is bound to occur.

Could you check if there are any issues in your Page_Load .

subi_speedrunner
  • 901
  • 3
  • 9
  • 17