What I am trying to do is very simple and logical.
I have a web page with two panels. Panel1 is used for user controls ddl, tb etc and used to help the user to build records to be inserted into database. Once the user completes Panel1 entries they use the submit button to upload the records into SQL datasource.
The submit button load the new rcords into the SQL DS and also hides Panel1 and diaplays Panel2. Panel2 is just a basic gridview used to show the user the records that were uploaded. They can also EDIT the records here to make any last minute changes. This
is all done on the same webpage just using visble panels. This works perfect!
The problem arises when the user hits the refresh key combo (F5) or browser refresh during panel2 gridview. ASP reposts the same records again to the database but with new numbers. The new numbers are appled because I have a function that runs on the fly
in submit section to check the database for the last number so that new records never step on or conflict with the existing ones.
Because of this design I have the problem where the user can duplicate 1 or more records at a shot - could be thousands! Ouch!
I have scanned the internet and reas so many posts but cannot seam to find a method that stops this.
In my mind I want to possibly set a session value with GUID or similar so that it can be compared at the time of submit button . I tried this with sample session and viewstate date values. This did not work. I tried set the sesion value during submit button
and set the viewstate during not isPostBack (basially set the viewstate data value for first page load) then test compare of the two during the submit button. if they are not equal I perform the inserting else nothing is done. But I had a hard time getting
the viewstate recognized. Not really sure how all this did work.
Bbut someone must have someresolve for this because this seems like a very well know problem to everyone.
Please any suggestions or working examples are welcome.
You can check the values are alredy exists on DataBase server before inserting , if it not then you can insert the value , if value exists and has been modified then you can update the value.
Like
IF EXISTS(select top 1 1 from TableName where columnId = @CloumnId)
No this will definitely not work. I as mentioned in the original post the submit button checks the existing records and finds the greatest number of the key and resets this number so what happens is new records are added. So checking record exist will not
work!
I added the following to the end of the sub for the button submit. I then tested the submit and then pressed F5 browser refresh and still the insertion occurs. I also pressed back page andthe same problem so unfortuantely this did not work. Am i missing
something.
e.g
Protected Sub ButtonSubmitGenerate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonSubmitGenerate.Click
... blah blah my code to insert data.... to SQL...
The only other thing I can think of is to try changing the submit button to be disabled or set session variables to the values submitted and compare on each new postback. If all of the fields match then don't insert into the database.
gogginl
Member
79 Points
258 Posts
Prevent refresh following Submit button - Cannot find a solution to work
Jan 09, 2013 04:50 PM|LINK
What I am trying to do is very simple and logical.
I have a web page with two panels. Panel1 is used for user controls ddl, tb etc and used to help the user to build records to be inserted into database. Once the user completes Panel1 entries they use the submit button to upload the records into SQL datasource. The submit button load the new rcords into the SQL DS and also hides Panel1 and diaplays Panel2. Panel2 is just a basic gridview used to show the user the records that were uploaded. They can also EDIT the records here to make any last minute changes. This is all done on the same webpage just using visble panels. This works perfect!
The problem arises when the user hits the refresh key combo (F5) or browser refresh during panel2 gridview. ASP reposts the same records again to the database but with new numbers. The new numbers are appled because I have a function that runs on the fly in submit section to check the database for the last number so that new records never step on or conflict with the existing ones.
Because of this design I have the problem where the user can duplicate 1 or more records at a shot - could be thousands! Ouch!
I have scanned the internet and reas so many posts but cannot seam to find a method that stops this.
In my mind I want to possibly set a session value with GUID or similar so that it can be compared at the time of submit button . I tried this with sample session and viewstate date values. This did not work. I tried set the sesion value during submit button and set the viewstate during not isPostBack (basially set the viewstate data value for first page load) then test compare of the two during the submit button. if they are not equal I perform the inserting else nothing is done. But I had a hard time getting the viewstate recognized. Not really sure how all this did work.
Bbut someone must have someresolve for this because this seems like a very well know problem to everyone.
Please any suggestions or working examples are welcome.
sen338
Member
498 Points
118 Posts
Re: Prevent refresh following Submit button - Cannot find a solution to work
Jan 09, 2013 05:03 PM|LINK
Hi,
You can check the values are alredy exists on DataBase server before inserting , if it not then you can insert the value , if value exists and has been modified then you can update the value.
Like
IF EXISTS(select top 1 1 from TableName where columnId = @CloumnId)
Begin
If Not Exists(select top 1 1 from TableName where columnId=@cloumnId and Column1=@cloumn1 and column2=@Column2) --like this
update set column1=@column1 , column2=@cloumn2 tablenama where columnId = @ColumnId
End
End
ELSE
Begin
Inser Query
ENd
gogginl
Member
79 Points
258 Posts
Re: Prevent refresh following Submit button - Cannot find a solution to work
Jan 09, 2013 05:21 PM|LINK
No this will definitely not work. I as mentioned in the original post the submit button checks the existing records and finds the greatest number of the key and resets this number so what happens is new records are added. So checking record exist will not work!
kraznodar
Contributor
3332 Points
881 Posts
Re: Prevent refresh following Submit button - Cannot find a solution to work
Jan 09, 2013 07:06 PM|LINK
Do all of the no cache things like:
Page.Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.Expires = 0
Response.Cache.SetNoStore()
Response.AppendHeader("Pragma", "no-cache")
This should theoretically expire the page so there is nothing to submit.
sen338
Member
498 Points
118 Posts
Re: Prevent refresh following Submit button - Cannot find a solution to work
Jan 09, 2013 07:15 PM|LINK
pelase check the below link
http://dotnetslackers.com/community/blogs/simoneb/archive/2007/01/07/Using-an-HttpModule-to-detect-page-refresh.aspx
http://forums.asp.net/t/1184197.aspx/3/10
gogginl
Member
79 Points
258 Posts
Re: Prevent refresh following Submit button - Cannot find a solution to work
Jan 09, 2013 08:29 PM|LINK
I added the following to the end of the sub for the button submit. I then tested the submit and then pressed F5 browser refresh and still the insertion occurs. I also pressed back page andthe same problem so unfortuantely this did not work. Am i missing something.
e.g
Protected Sub ButtonSubmitGenerate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonSubmitGenerate.Click
... blah blah my code to insert data.... to SQL...
Page.Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.Expires = 0
Response.Cache.SetNoStore()
Response.AppendHeader("Pragma", "no-cache")
End Sub
kraznodar
Contributor
3332 Points
881 Posts
Re: Prevent refresh following Submit button - Cannot find a solution to work
Jan 10, 2013 06:32 PM|LINK
The only other thing I can think of is to try changing the submit button to be disabled or set session variables to the values submitted and compare on each new postback. If all of the fields match then don't insert into the database.