Link to home
Start Free TrialLog in
Avatar of JDEE8297
JDEE8297Flag for United States of America

asked on

allowing no postbacks if the user does a browser refresh

Greetings,

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?
Avatar of Göran Andersson
Göran Andersson
Flag of Sweden image

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.
Avatar of JDEE8297

ASKER

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.

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: http://www.codeproject.com/KB/cpp/BrowserRefreshASPdotNET.aspx
tedbilly,

I know all about the use of asp.net 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.
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
ASKER CERTIFIED SOLUTION
Avatar of Göran Andersson
Göran Andersson
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks for your help.