We help IT Professionals succeed at work.
Get Started

How to handle page refresh in ASP.NET

Last Modified: 2013-11-08
I have a ImageButton(submit) and a FileUpload controls on my ASP.NET page.
When the user upload a file and clicks the Image button it gets into the Submit_File button click which is tied to the ImageButton click event.

When the user refreshes the page it also gets into the submit click event which I want to prevent.

How can I do this

I tied the following in the code behind, and this prevents the refresh, but prevents a new file being processed, bcos after the first submit and any subsequent refreshes the Session["Submitted"] = true
if (!Page.IsPostBack)
if (Session["Submitted"] == null)
                Session.Add("Submitted", false);
                Session["Submitted"] = false;

submit_click event(object sender, eventargs e)
 if ((Session["Submitted"] == null) || (Convert.ToBoolean(Session["Submitted"]) == false))
        else { return; }

 Session.Add("Submitted", true);

I also tried adding a second hidden button with a click event but it always gets into the Submit_file click
Watch Question
Chief Technology Ninja
Distinguished Expert 2020
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE