Click here to Skip to main content
15,921,793 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: Avoid Duplicate record insertion on page refresh(F5) Pin
Rhys Jacob16-Feb-10 1:35
Rhys Jacob16-Feb-10 1:35 
AnswerRe: Avoid Duplicate record insertion on page refresh(F5) Pin
Brij16-Feb-10 1:40
mentorBrij16-Feb-10 1:40 
GeneralRe: Avoid Duplicate record insertion on page refresh(F5) Pin
Anurag Gandhi16-Feb-10 1:50
professionalAnurag Gandhi16-Feb-10 1:50 
GeneralRe: Avoid Duplicate record insertion on page refresh(F5) Pin
Brij16-Feb-10 2:04
mentorBrij16-Feb-10 2:04 
AnswerRe: Avoid Duplicate record insertion on page refresh(F5) Pin
Dinesh Mani16-Feb-10 2:33
Dinesh Mani16-Feb-10 2:33 
GeneralRe: Avoid Duplicate record insertion on page refresh(F5) Pin
amitamit09916-Feb-10 3:00
amitamit09916-Feb-10 3:00 
AnswerRe: Avoid Duplicate record insertion on page refresh(F5) Pin
bgates197016-Feb-10 4:55
bgates197016-Feb-10 4:55 
AnswerRe: Avoid Duplicate record insertion on page refresh(F5) [modified] Pin
Member 103390716-Feb-10 9:29
Member 103390716-Feb-10 9:29 
I invested some time investigating this and the only solution I found working is based on some interaction between client data (ViewState, ...) and server data (Session, ...). Why:

- I don't accept solutions like "Check if the record already exists in the database" etc., because this is limited to inserting data to database, useless for any other scenario. Plus it has other flaws.
- You can't rely solely on client data (by this I mean data received from the client, like ViewState, POST data etc.), because when the user hits F5, the same request with the exact same data is sent to the server - if you accept the request as genuine the first time (and insert some data to the database), there is no way to dismiss it the second time (after refresh) because the data is exactly the same, so any deterministic algorithm for refresh detection can't possibly work. Half the people in the posts above don't realize this.
- I don't accept page redirections, because they either don't work (see above, try yourself if you don't believe) or if you try hard and make them work, they destroy the page state so it may be difficult to keep track of where the user was in the application, etc.

This eliminates all the solutions from the above posts. Like I said, the only way I got to work was to maintain a state-interaction between some Session variable (or any server piece of data) and ViewState variable (or any client piece of data). During normal requests, you keep these in sync and when you receive some Insert request, you compare them and check if they are in sync. If they are, the request is genuine and you can perform the insert. If the user hits Refresh (F5), the ViewState data is old compared to the server data and you recognize the request as refresh and do not perform the insert.
I event made a small component for this purpose, which you simply add to the page and then call BlahBlah.IsRefresh whenever you need. I can publish it somewhere if anyone cares. I think Microsoft should have long ago addded this functionality to the Framework so we could call Page.IsRefresh just like Page.IsPostback.
modified on Wednesday, February 17, 2010 3:56 AM

GeneralRe: Avoid Duplicate record insertion on page refresh(F5) Pin
amitamit09916-Feb-10 19:03
amitamit09916-Feb-10 19:03 
Questionbind Checkboxes Pin
m@dhu15-Feb-10 22:03
m@dhu15-Feb-10 22:03 
AnswerRe: bind Checkboxes Pin
Brij15-Feb-10 22:16
mentorBrij15-Feb-10 22:16 
AnswerRe: bind Checkboxes Pin
Dinesh Mani15-Feb-10 22:17
Dinesh Mani15-Feb-10 22:17 
AnswerRe: bind Checkboxes Pin
keyur satyadev15-Feb-10 22:52
keyur satyadev15-Feb-10 22:52 
QuestionWeb Deployment error for WebUserControl event [modified] Pin
K V Sekhar15-Feb-10 21:29
K V Sekhar15-Feb-10 21:29 
AnswerRe: Web Deployment error for WebUserControl event Pin
Dinesh Mani15-Feb-10 21:47
Dinesh Mani15-Feb-10 21:47 
GeneralRe: Web Deployment error for WebUserControl event Pin
K V Sekhar15-Feb-10 21:55
K V Sekhar15-Feb-10 21:55 
GeneralRe: Web Deployment error for WebUserControl event Pin
Dinesh Mani15-Feb-10 22:07
Dinesh Mani15-Feb-10 22:07 
GeneralRe: Web Deployment error for WebUserControl event Pin
K V Sekhar15-Feb-10 22:58
K V Sekhar15-Feb-10 22:58 
GeneralRe: Web Deployment error for WebUserControl event [modified] Pin
Dinesh Mani15-Feb-10 23:03
Dinesh Mani15-Feb-10 23:03 
GeneralRe: Web Deployment error for WebUserControl event Pin
K V Sekhar16-Feb-10 2:04
K V Sekhar16-Feb-10 2:04 
GeneralRe: Web Deployment error for WebUserControl event Pin
Dinesh Mani16-Feb-10 2:24
Dinesh Mani16-Feb-10 2:24 
GeneralRe: Web Deployment error for WebUserControl event Pin
K V Sekhar16-Feb-10 3:17
K V Sekhar16-Feb-10 3:17 
AnswerRe: Web Deployment error for WebUserControl event Pin
Nath15-Feb-10 23:50
Nath15-Feb-10 23:50 
GeneralRe: Web Deployment error for WebUserControl event Pin
K V Sekhar16-Feb-10 2:05
K V Sekhar16-Feb-10 2:05 
GeneralRe: Web Deployment error for WebUserControl event Pin
amitamit09916-Feb-10 18:56
amitamit09916-Feb-10 18:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.