allowing no postbacks if the user does a browser refresh


What I am trying to do is prevent the form from doing a postback on a browser refresh after the user has already submitted the form. Is this possible to do?
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

Göran AnderssonConnect With a Mentor Commented:
You don't have to user a session variable, but you have to store the information on the server some way. Perhaps in a database?

The solution that tedbilly linked to doesn't work at all. You can't use a static variable to store user specific data in a web application. (I also left a message in the article explaining this.)
Göran AnderssonCommented:
No, that is not possible. The browser can always do a refresh, and that sends another request to the server with the same data as the last request.

What you can do is to save some data on the server, so that you can detect if it's a repeating request that is coming to the server.

For example saving the time when a reuqest is accepted in a session variable and also put the value in a hidden field in the form, and only accept requests where the hidden value corresponds with value in the session varable.
JDEE8297Author Commented:
trying to avoid session variables if at all possible. You see this could live in a web farm and the use of session variables (although possible) is not desirable in this application. So I am trying to come up with a work around for it.

Your solution with the hidden form field sounds good,  but again I have some examples using session variables and view state and although they seem to work. they do seem like a hack. Tis amazing that this problem has been resolved in the framework, because I know that this is not thefirst time I have ran into it.

Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Ted BouskillSenior Software DeveloperCommented:
In regard to a farm, you should consider using the ASP.NET session state service or a SQL data source for sessions.  Building web applications on a farm without sessions restricts your choices.  OR, if you setup your farm with Windows NLB (Network Load Balancing) you can create sticky sessions.  In other words is UserA starts a session on ServerA, they will always return to ServerA.  It's called 'Affinity'

By the way, here is an article that solves your problem:
JDEE8297Author Commented:

I know all about the use of session state and sql data for storing state or setting up NLB to do sticky sessions. the problem is that I have brought up all of these options for storing session, each one has been shot down because it involves using session objects.

So I was looking for something that didn't do session or anything like that. the link you gave looks promising and I will try that out at my work place tomorrow. I will let you know how it went.
Ted BouskillSenior Software DeveloperCommented:
I just wanted to be sure you were aware of your choices.  That wasn't clear in the question or previous comments.  Session objects can often be abused so many people go the opposite route and ban them.  Ulimately, you have to work with what you are given for requirements.

I've used a combination of cookies and hidden form values to eliminate sessions.  It is possible just a bit of a challenge.

I'm confident that link will do what you need.  Cheers
JDEE8297Author Commented:
thanks for your help.
All Courses

From novice to tech pro — start learning today.