views:

79

answers:

6

Is something in the http protocol that will help me find out, or should I check the fields by myself.

If identical field values can be submitted more than once, should I add a dummy hidden field or something?

A: 

One way you could do so is, disable the button using JavaScript once its clicked. Also, you can make a server side code which checks for multiple submits (or postbacks). I dont think there is anything available on the HTTP protocol as HTTP is stateless and doesnt know by itself about multiple submits.

Bhaskar
thank you for the javascript idea. but this won't help if the user reloads the page after the post has been submitted, will it?
flybywire
Well, thats when you can write a small script to check for the user reload status. Like, you can simply create a session variale which stores the current page the session is vieweing. And you can put checks based on that.
Bhaskar
A: 

I dont think its possible in http. you can calculate a hash of the fields and check it in javascript.

Edit you can store it in cookies

Umair Ahmed
+3  A: 

If you want to be completely sure you'll need to include a unique id for the form in a hidden field in the form, and check it against a data store all server threads can see (e.g. a db) before handling the form data.

Jim Downing
A: 

One way to avoid this is to make a redirect to the same page after the occurrence of a postback action. But this will clear all your values stored in the ViewState.

Here is a good article on this subject

Build your ASP.NET Pages on a Richer Bedrock

rahul
A: 

You can solve the problem on the client, on the server or both.

Client-side you can disable the submit button, show an alert box, redirect the user etc - have a look at this article.

Server-side you can use sessions and allow each visitor to submit only once.

Anax
A: 

I generally don't worry about extra loads/submits unless data is being saved/changed. As a result I put strong controls in the data modification logic. When loading the data I return the last change date and time of that data. When saving, I make sure that the existing data has the same exact last change date. the second save/change will be aborted because the first save will modify this last change date making it different. In the case of initial saving (INSERT) you can add logic to make sure that there has not been a new item created for the user within the last X time.

KM