1

i"m using asp.net FileUpload , after user input file he click on save button

in the c# i have this function

 protected void btnUploadImages_Click(object sender, EventArgs e)
    {
     SaveImages(FileUpload1, "", returnAlbumId, out returnPhotoId);
    }

this function save the image from the FileUpload1 so far all work as it"s should

but after the postback when i push the refresh button on the page i"m go to this function again , SaveImages function save the same image again . the FileUpload1 didn't clear after the postback

thanks

KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
avnic
  • 3,241
  • 8
  • 37
  • 46
  • 2
    possible duplicate of [How to prevent repeated postbacks from confusing my business layer](http://stackoverflow.com/questions/481564/how-to-prevent-repeated-postbacks-from-confusing-my-business-layer) – Paŭlo Ebermann Sep 04 '11 at 13:59

1 Answers1

0

Even i got the Same Problem I have resolved like Below.

After uploading the File If you Redirect to same page or some other page in your project. After Redirection Response will not be there once you redirected.

In My ASPX

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm.aspx.cs" Inherits="WebApplication.WebForm" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>

<body>
    <form id="form1" runat="server">
        <div>
            <asp:FileUpload ID="FileUpload1" runat="server" />
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
        </div>
    </form>
</body>
</html>

In My Code Behind

 public partial class WebForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string path = Server.MapPath("~");
            path = path + FileUpload1.FileName;
            FileUpload1.SaveAs(path);
            Response.Redirect("WebForm.aspx"); // Responce will be cleared. This Redirection will do the Trick 
            //Put the debugger and check it will work
        }
    }

Here, to show the success and error messages try to use sessions.

RajeshKdev
  • 6,365
  • 6
  • 58
  • 80